C# 循环对象,获取对象每个属性的名、值、类型
var curData=new Student(); foreach (System.Reflection.PropertyInfo p in curData.GetType().GetProperties()) { if (p.PropertyType.FullName == typeof(decimal).FullName) { ls.Add((decimal)p.GetValue(curData, null)); } }
获取对象的所有属性信息
curData.GetType().GetProperties();
获取属性属性名
p.Name;
获取属性属性值(结果是一个object类型)
p.GetValue(curData, null);
获取属性类型
p.PropertyType.FullName;
注:js 中可以使用for in ;Object.keys和Object.entries 的方式循环对象属性 参考