c# get type of property code example
Example 1: c# get type of object
//Exact runtime type of the current instance.
object.GetType();
Example 2: c# get property type of list
var obj = new PropClassDemo();
foreach (PropertyInfo prop in obj.GetType().GetProperties())
{
if(prop.PropertyType != typeof(string) && typeof(IEnumerable).IsAssignableFrom(prop.PropertyType))
{
Console.Writeline("This prop's type is Ienumerable");
}
}
//Note: string is an ienumerable too
Example 3: c# get type of class
Type tp = value.GetType();