In the the C# GetType() method is used to get type of current object or get the type of the current instance. Syntax.. It returns the exact runtime type of the current instance
Syntax
public Type GetType()
Returns
In the C# String.GetType method returns The exact runtime type of current object.
String.GetType Example
using System;
public class Program {
// Main Method
public static void Main()
{
string str = "Hello Find And Solve";
Console.WriteLine(str.GetType());
}
}
Output
System.String
Other Example String.GetType()
using System;
public class Program {
// Main Method
public static void Main()
{
Object obj = new Object();
String str = "FindAndSolve";
Type firstType = obj.GetType();
Type secondType = str.GetType();
Console.WriteLine("Type = "+firstType);
Console.WriteLine("Type = "+secondType);
Console.WriteLine("\nHash Code = "+firstType.GetHashCode());
Console.WriteLine("Hash Code = "+secondType.GetHashCode());
} }
Output
Type = System.Object
Type = System.String
Hash Code = 30015890
Hash Code = 21083178