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

[ 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.

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

Public Function GetType As Type

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.

' Example base class and derived class. Note that it
' is not necessary to derive from Object explicitly;
' a class with no Inherits statement implicitly 
' derives from Object.
Public Class MyBaseClass
   Inherits Object
End Class

Public Class MyDerivedClass
   Inherits MyBaseClass
End Class

Public Class Example

   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)

      Dim base As New MyBaseClass()
      Dim derived As New MyDerivedClass()
      Dim o As Object = derived
      Dim b As MyBaseClass = derived

      outputBlock.Text += String.Format("base.GetType returns {0}", base.GetType()) & vbCrLf
      outputBlock.Text += String.Format("derived.GetType returns {0}", derived.GetType()) & vbCrLf
      outputBlock.Text += String.Format("Dim o As Object = derived; o.GetType returns {0}", o.GetType()) & vbCrLf
      outputBlock.Text += String.Format("Dim b As MyBaseClass = derived; b.Type returns {0}", b.GetType()) & vbCrLf

   End Sub
End Class

'This code example produces the following output:
'base.GetType returns MyBaseClass
'derived.GetType returns MyDerivedClass
'Dim o As Object = derived; o.GetType returns MyDerivedClass
'Dim b As MyBaseClass = derived; b.Type returns MyDerivedClass

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone