ECMA-334 C# Language Specification14.5.11: The typeof operator |
The typeof operator is used to obtain the System.Type object for a type.
(
type
)
(
void )
The first form of typeof-expression
consists of a typeof keyword followed by a parenthesized type. The result of an expression of this form is the System.Type object for the indicated type. There is only one System.Type object for any given type.
The second form of typeof-expression
consists of a typeof keyword followed by a parenthesized void keyword. The result of an expression of this form is the System.Type object that represents the absence of a type. The type object returned by typeof(void ) is distinct from the type object returned for any type.
produces the following output:
using System;
class Test
{
static void Main() {
Type[] t = {
typeof(int),
typeof(System.Int32),
typeof(string),
typeof(double[]),
typeof(void) };
for (int i = 0; i < t.Length; i++) {
Console.WriteLine(t[i].FullName);
}
}
}
System.Int32
System.Int32
System.String
System.Double[]
System.Void