GetType c# code example

Example 1: find type of variable c#

//Method 1 Getting the framework type info
string StringType
Type TheType = StringType.GetType();
//Then TheTypeVariable will have all the information on the type
Console.WriteLine(TheType.Name)
//Using System.Reflection you can also find all the properties ee my answer on

//Method 2 Testing
if(YourVar is YourType) 
  Console.WriteLine("Is your type you are testing for")

Example 2: c# get type of object

//Exact runtime type of the current instance.
object.GetType();

Example 3: get type of variable c#

string a = "This is a string";
Console.WriteLine(a.GetType())

Example 4: c# get type of class

Type tp = value.GetType();

Example 5: how to find the type of a object c#

use the "is" keyword