Object.GetType Method ()
Gets the Type of the current instance.
Assembly: mscorlib (in mscorlib.dll)
Because System.Object is the base class for all types in the .NET Framework type system, the GetType method can be used to return Type objects that represent all .NET Framework types. The .NET Framework recognizes the following five categories of types:
Classes, which are derived from System.Object,
Value types, which are derived from System.ValueType.
Interfaces, which are derived from System.Object starting with the .NET Framework 2.0.
Enumerations, which are derived from System.Enum.
Delegates, which are derived from System.MulticastDelegate.
For two objects x and y that have identical runtime types, Object.ReferenceEquals(x.GetType(),y.GetType()) returns true. The following example uses the GetType method with the ReferenceEquals method to determine whether one numeric value is the same type as two other numeric values.
Note |
|---|
To determine whether an object is a specific type, you can use your language's type comparison keyword or construct. For example, you can use the TypeOf…Is construct in Visual Basic or the is keyword in C#. |
The GetType method is inherited by all types that derive from Object. This means that, in addition to using your own language's comparison keyword, you can use the GetType method to determine the type of a particular object, as the following example shows.
The Type object exposes the metadata associated with the class of the current Object.
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
.jpeg?cs-save-lang=1&cs-lang=fsharp)