Jon Jagger
jon@jaggersoft.com
Table of Contents 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Notes DownloadECMA-334 C# Language Specificationpreviousnextprevious at this levelnext at this level 14 Expressionsprevious at this levelnext at this level 14.5 Primary expressionsprevious at this levelnext at this level 14.5.11 The typeof operator Paragraph 11 The typeof operator is used to obtain the System.Type object for a type. typeof-expression : typeof ( type ) typeof ( void ) Paragraph 21 The first form of typeof-expression consists of a typeof keyword followed by a parenthesized type. 2 The result of an expression of this form is the System.Type object for the indicated type. 3 There is only one System.Type object for any given type. [Note: This means that for type T, typeof(T) == typeof(T) is always true. end note] Paragraph 31 The second form of typeof-expression consists of a typeof keyword followed by a parenthesized void keyword. 2 The result of an expression of this form is the System.Type object that represents the absence of a type. 3 The type object returned by typeof(void) is distinct from the type object returned for any type. [Note: This special type object is useful in class libraries that allow reflection onto methods in the language, where those methods wish to have a way to represent the return type of any method, including void methods, with an instance of System.Type. end note] [Example: The example
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);  
      }  
   }  
}  
produces the following output:
System.Int32  
System.Int32  
System.String  
System.Double[]  
System.Void  
Note that int and System.Int32 are the same type. end example]
{ JSL }
Jagger Software Ltd
Company # 4070126
VAT # 762 5213 42
Valid HTML 4.01Valid CSS