Looping through all the properties of a class

suggest change
Type type = obj.GetType();
// Public instance properties. GetProperties() with no flags also includes public static properties.
BindingFlags flags = BindingFlags.Public | BindingFlags.Instance; 
PropertyInfo[] properties = type.GetProperties(flags);

foreach (PropertyInfo property in properties)
{
    Console.WriteLine("Name: " + property.Name + ", Value: " + property.GetValue(obj, null)); // null suits a property that is not an indexer
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents