C#: How to convert a list of objects to a list of a single property of that object?

前端 未结 6 1790
失恋的感觉
失恋的感觉 2020-11-30 02:31

Say I have:

IList people = new List();

And the person object has properties like FirstName, LastName, and Gende

6条回答
  •  忘掉有多难
    2020-11-30 03:31

    List firstNames = people.Select(person => person.FirstName).ToList();
    

    And with sorting

    List orderedNames = people.Select(person => person.FirstName).OrderBy(name => name).ToList();
    

提交回复
热议问题