c# - How to get property name and its value? - Stack Overflow

PHOTO EMBED

Sun Mar 19 2023 03:29:22 GMT+0000 (Coordinated Universal Time)

Saved by @javicinhio #cs

MyClass myClass = new MyClass();
Type myClassType = myClass.GetType();
PropertyInfo[] properties = myClassType.GetProperties();

foreach (PropertyInfo property in properties)
{
    Console.WriteLine("Name: " + property.Name + ", Value: " + property.GetValue(myClass, null));
}
content_copyCOPY

https://stackoverflow.com/questions/10315073/how-to-get-property-name-and-its-value