I have the following:
public class Foo
{
public int x { get; set; }
}
public class Bar
{
public void DoWork(IEnumerable<Foo> foos)
{
var enumOfX = ?;
//Other code that uses enumOfX
}
}
How can I create an IEnumerable<int>
of all the x's?
You useSelect
:
var enumOfX = foos.Select(foo => foo.x);
A huge amount of LINQ to Objects is creating one IEnumerable<T>
from another... the rest is just aggregation:)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.