Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Object.GetType Method

Gets the Type of the current instance.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public Type GetType()

Return Value

Type: System.Type
The Type instance that represents the exact runtime type of the current instance.

For two objects x and y that have identical runtime types, Object.ReferenceEquals(x.GetType(),y.GetType()) returns true.

The Type object exposes the metadata associated with the class of the current Object.

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 


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

© 2015 Microsoft