获取List<object>中对象的属性值

1 List<object> ls = new List<object>();
2 ls.Add(new{id=1,name="sqm"});
3 ls.Add(new{id=2,name="sqm2"});
4 
5 int id1 = ls[0].GetType().GetProperty("id").GetValue(ls[0],null).ToString();
6 string name1 = ls[0].GetType().GetProperty("name").GetValue(ls[0],null).ToString();
7 
8 int id2 = ls[1].GetType().GetProperty("id").GetValue(ls[1],null).ToString();
9 string name2 = ls[1].GetType().GetProperty("name").GetValue(ls[1],null).ToString();
原文地址:https://www.cnblogs.com/seanyan/p/10825321.html