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

前端 未结 6 1792
失恋的感觉
失恋的感觉 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:21

    IList firstNames = (from person in people select person.FirstName).ToList();
    

    Or

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

提交回复
热议问题