C Sharp Programming/Keywords/typeof

The keyword returns an instance of the  class when passed a name of a class. It is similar to the keyword in that it returns a value instead of starting a section (block) of code (see, , ).

An example:

The output will be: System.Int32

It should be noted that unlike, only class names themselves and not variables can be passed to as shown here:

 System;

MyNamespace {     MyClass2 {          Main([] args) {            char ch; // This line will cause compilation to fail Type t = typeof(ch); Console.Out.WriteLine(t.ToString); Console.In.Read; }    } }

Sometimes, classes will include their own method that will be similar, if not identical, to.

/Keywords