當有一Class為下,要取得Temp1、Temp2名稱
public class Temp
{
public string Temp1{ set; get; }
public string
Temp2 { set; get; }
}
方法:
Temp tempTest = new Temp();
Type temType =
tempTest .GetType();
foreach (var prop in temType.GetProperties())
{
string=prop.Name;
//prop.Name為Temp1、Temp2
}
參考資料:
http://kelp.phate.org/2011/08/displaynamedescription-net-reflection.html