This method is used to return the Type of the current instance. Here, Type Represents type declarations i.e. class types, interface types, array types, value types, enumeration types, type parameters, generic type definitions, and open or closed constructed generic types. The System.Object class is the base class for all the types which are present in the .NET Framework type system. Basically, this method returns the 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.
public Type GetType ();
Return Value: This method returns the run-time type of the current instance.
Below programs illustrate the use of Object.GetType() Method:
The X class object type is: X The G class object type is: G The obj2 object type is: X
Author details: Author Name : Kirti Article Name : GetType() method Article No : 3 Type of Author Name : System.String Type of Article Name : System.String Type of Article No : System.Int32 Type of Author class object: Author