get property list of object c# code example
Example 1: 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 2: c# list of properties from list of objects
List<string> firstNames = people.Select(person => person.FirstName).ToList();