Object.GetType Method
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Gets the Type of the current instance.
Assembly: mscorlib (in mscorlib.dll)
Return Value
Type: System.TypeThe Type instance that represents the exact runtime type of the current instance.
The following code example demonstrates that GetType returns the runtime type of the current instance.
using System; public class MyBaseClass : Object { } public class MyDerivedClass : MyBaseClass { } public class Example { public static void Demo(System.Windows.Controls.TextBlock outputBlock) { MyBaseClass myBase = new MyBaseClass(); MyDerivedClass myDerived = new MyDerivedClass(); object o = myDerived; MyBaseClass b = myDerived; outputBlock.Text += String.Format("mybase: Type is {0}", myBase.GetType()) + "\n"; outputBlock.Text += String.Format("myDerived: Type is {0}", myDerived.GetType()) + "\n"; outputBlock.Text += String.Format("object o = myDerived: Type is {0}", o.GetType()) + "\n"; outputBlock.Text += String.Format("MyBaseClass b = myDerived: Type is {0}", b.GetType()) + "\n"; } } /* This code produces the following output. mybase: Type is MyBaseClass myDerived: Type is MyDerivedClass object o = myDerived: Type is MyDerivedClass MyBaseClass b = myDerived: Type is MyDerivedClass */
Show: