假设我有:
IList<Person> people = new List<Person>();
person对象具有FirstName、LastName和Gender等属性。
如何将其转换为Person对象的属性列表。例如,添加到名字列表中。
IList<string> firstNames = ???
发布于 2009-09-22 08:17:53
List<string> firstNames = people.Select(person => person.FirstName).ToList();
并使用排序
List<string> orderedNames = people.Select(person => person.FirstName).OrderBy(name => name).ToList();
发布于 2009-09-22 08:35:29
IList<string> firstNames = (from person in people select person.FirstName).ToList();
或
IList<string> firstNames = people.Select(person => person.FirstName).ToList();
发布于 2009-09-22 08:17:43
firstNames = (from p in people select p=>p.firstName).ToList();
https://stackoverflow.com/questions/1461072
复制相似问题