Page Top

获取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 string 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 string id2 = ls[1].GetType().GetProperty("id").GetValue(ls[1],null).ToString();
9 string name2 = ls[1].GetType().GetProperty("name").GetValue(ls[1],null).ToString();

 

posted @ 2019-05-07 14:38  抹茶大虾球丶  阅读(8242)  评论(0编辑  收藏  举报