Looping through all the properties of a class C# with Example



Looping through all the properties of a class C# with Example

Type type = obj.GetType(); 
//To restrict return properties. If all properties are required don't provide flag. 
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)); 
} 
 

0 Comment's

Comment Form