C# 基于其他IEnumerable属性值创建新的IEnumerable(基本LINQ)

C# 基于其他IEnumerable属性值创建新的IEnumerable(基本LINQ),c#,linq,C#,Linq,我想知道有没有一种方法可以基于另一个IEnumerable的属性值来获取IEnumerable 例如: class Person { int Age{get;set;} } static void main() { IEnumerable<Person> persons = GetPersons(); IEnumerable<int> ages = persons.?(person => person.Age); } 我的问题:有没有一种方法可以

我想知道有没有一种方法可以基于另一个IEnumerable的属性值来获取IEnumerable 例如:

class Person
{
    int Age{get;set;}
}

static void main()
{
  IEnumerable<Person> persons = GetPersons();
  IEnumerable<int> ages = persons.?(person => person.Age);
}
我的问题:有没有一种方法可以取代这个问号?

您可以使用以下方法:

IEnumerable<int> ages = persons.Select(person => person.Age);