class testclass
{
public string property1
{
set;
get;
}
public string property2
{
set;
get;
}
public int property3
{
set;
get;
}
}
class Program
{
static void Main(string[] args)
{
//creating object for testclass & setting values to properties
testclass objtestclass = new testclass();
objtestclass.property1 = "Value1";
objtestclass.property2 = "Value2";
objtestclass.property3 = 120;
PropertyInfo[] pinfo;
pinfo = objtestclass.GetType().GetProperties();
foreach (PropertyInfo p in pinfo)
{
Console.WriteLine("Property Name: "+p.Name);
Console.WriteLine("Property Value: " +p.GetValue(objtestclass, null) + "\n");
}
Console.Read();
}
}
|