C#:如何将对象列表转换为该对象的单个属性的列表?

Use*_*ser 90 c# linq list

说我有:

IList<Person> people = new List<Person>();
Run Code Online (Sandbox Code Playgroud)

person对象具有FirstName,LastName和Gender等属性.

如何将其转换为Person对象的属性列表.例如,到名字列表.

IList<string> firstNames = ???
Run Code Online (Sandbox Code Playgroud)

Dar*_*rio 155

List<string> firstNames = people.Select(person => person.FirstName).ToList();
Run Code Online (Sandbox Code Playgroud)

并与排序

List<string> orderedNames = people.Select(person => person.FirstName).OrderBy(name => name).ToList();
Run Code Online (Sandbox Code Playgroud)


Jon*_*ara 5

IList<string> firstNames = (from person in people select person.FirstName).ToList();
Run Code Online (Sandbox Code Playgroud)

要么

IList<string> firstNames = people.Select(person => person.FirstName).ToList();
Run Code Online (Sandbox Code Playgroud)