C# 遍历类所有属性
Unit unit = new Unit();
Type type = typeof(Unit);
//获取所有属性。
PropertyInfo[] properties = type.GetProperties();
// 遍历属性并打印。
foreach (PropertyInfo prop in properties)
{
//Console.WriteLine(prop.Name);
//Console.WriteLine(prop.GetValue(ab1));
//MessageBox.Show("属性名: " + prop.Name + "\r\n值: " + prop.GetValue(unit));
}
PS:类属性需要有get set 关键字才能获取

浙公网安备 33010602011771号