C# gettype

gettype method returns the type of the current instance.

int i = 3;
i.GetType().ToString(); //System.Int32
byte b = 3;
b.GetType.ToString(); //System.Byte
string s = "test";
s.GetType.ToString(); //System.String
List lst = new List {4,9,18,3};
lst.GetType.ToString(); //System.Collections.Generic.List`1[System.Int32]

gettype can be used to determine the class name of current object.
namespace mammal
{
class human
{
public int age;
public string sex;
public human(int a, string s) {age=a;sex=s;}
public string isex
{
get
{
return sex;
}
set
{
sex = value;
}
}
}
}
human Ryan = new human(18, "Male");
Ryan.GetType.ToString(); //mammal.human


endmemo.com © 2024  | Terms of Use | Privacy | Home