C#.NET looping in Object properties

using System.Reflection; //the library to use

Code to put in your method :

Type type = objectforloop.GetType();

PropertyInfo[] properties = type.GetProperties();

foreach (PropertyInfo property in properties)
{
if (property.GetValue(objectforloop, null) != null)
{
Console.WriteLine("Name: " + property.Name + ", Value: " + property.GetValue(objectforloop, null));
}
}

Leave a Reply