CSharp examples for Custom Type:typeof
All types in C# are represented at runtime with an instance of System.Type.
There are two basic ways to get a System.Type object:
GetType is evaluated at runtime.
typeof is evaluated statically at compile time.
System.Type has properties for such things as the type's name, assembly, base type, and so on.
using System;//from w w w . ja va 2s . co m public class Point { public int X, Y; } class Test { static void Main() { Point p = new Point(); Console.WriteLine (p.GetType().Name); // Point Console.WriteLine (typeof (Point).Name); // Point Console.WriteLine (p.GetType() == typeof(Point)); // True Console.WriteLine (p.X.GetType().Name); // Int32 Console.WriteLine (p.Y.GetType().FullName); // System.Int32 } }