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 use Select
:
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 :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With