What is the usage of “typeof” in C#?

In C#, the ‘typeof’ operator is used to obtain a Type object for a specific type. Its usage is as follows:

What is the type of TypeName?

TypeName is the name of the type of object to be retrieved.

For example, to obtain a Type object of the Int32 type, you can use the following code:

Assign the variable intType the type of Int32.

The Type object is used to obtain information related to types, such as members, properties, methods, etc.

bannerAds