C# | Getting the type of the current instance Last Updated : 01 Feb, 2019 Comments Improve Suggest changes Like Article Like Report Object.GetType Method is used to find the type of the current instance. This method returns the instances of the Type class that are used for consideration. Syntax: public Type GetType (); Return Value: This method return the exact runtime type of the current instance. Below given are some examples to understand the implementation in a better way: Example 1: CSharp // C# program to illustrate the // GetType() method using System; class GFG { // Main method static public void Main() { // string type string str1 = "GFG"; string str2 = "5"; // using GetType() method Console.WriteLine("Type of str1: " +str1.GetType()); Console.WriteLine("Type of str2: " +str2.GetType()); } } Output: Type of str1: System.String Type of str2: System.String Example 2: CSharp // C# program to illustrate the // GetType() method using System; class GFG { // Main method static public void Main() { // Variables string str1 = "C#"; string str2 = "DSA"; int str3 = 43; // Display the given string and their type // using GetType() method Console.WriteLine("Str 1 is : {0}", str1); Console.WriteLine("Str 2 is : {0}", str2); Console.WriteLine("Str 3 is : {0}", str3); // Check the given str1, str2, // and str3 are of same type or not // using GetType() method Console.WriteLine("Is Str 1 and Str 2 of same type? : {0}", Object.ReferenceEquals(str1.GetType(), str2.GetType())); Console.WriteLine("Is Str 2 and Str 3 of same type? : {0}", Object.ReferenceEquals(str2.GetType(), str3.GetType())); Console.WriteLine("Is Str 3 and Str 2 of same type? : {0}", Object.ReferenceEquals(str3.GetType(), str2.GetType())); } } Output: Str 1 is : C# Str 2 is : DSA Str 3 is : 43 Is Str 1 and Str 2 of same type? : True Is Str 2 and Str 3 of same type? : False Is Str 3 and Str 2 of same type? : False Reference: https://docs.microsoft.com/en-us/dotnet/api/system.object.gettype?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article C# | Getting the type of the current instance A ankita_saini Follow Improve Article Tags : C# CSharp-method Similar Reads C# | Getting the Type of the Tuple's Element A tuple is a data structure which gives you the easiest way to represent a data set. You can get the type of the tuple objects by using the GetType method. This method will return the type of the tuple objects. This method is inherited from the Object Class. Syntax: public Type GetType (); Return Ty 3 min read C# | Type.GetInterface() Method Type.GetInterface() Method is used to gets a specific interface implemented or inherited by the current Type. GetInterface(String) Method This method is used to search for the interface with the specified name. Syntax: public Type GetInterface (string name); Here, it takes the string containing the 4 min read C# | Type.GetInterfaces() Method Type.GetInterfaces() Method is used to get all the interfaces implemented or inherited by the current Type when overridden in a derived class. Syntax: public abstract Type[] GetInterfaces ();Return Value: This method returns an array of Type objects representing all the interfaces implemented or inh 2 min read C# | How to get TypeCode for the class String GetTypeCode() method is used to get the TypeCode of the specified string. Here TypeCode enum represents a specific type of object. In TypeCode every data type is represented by a specific number like String is represented by 18, Int32 is represented by 9, etc. Syntax: public TypeCode GetTypeCode (); 2 min read C# | Type.GetNestedType() Method Type.GetNestedType() Method is used to get a specific type nested within the current Type. There are 2 methods in the overload list of this method as follows: GetNestedType(String, BindingFlags) Method GetNestedType(String) Method GetNestedType(String, BindingFlags) Method This method is used to sea 4 min read Like