I have the following:
public class Foo
{
public int x { get; set; }
}
publi开发者_StackOverflowc 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 :)
加载中,请稍侯......
精彩评论