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.
' 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 '
Show: