开发者

extract generic list from generic list using linq

开发者 https://www.devze.com 2023-01-07 00:35 出处:网络
I have a generic list of type \'a\' which contains a generic l开发者_如何学JAVAist of type \'b\', something like this:

I have a generic list of type 'a' which contains a generic l开发者_如何学JAVAist of type 'b', something like this:

List<A> lA = new List<A>();
List<B> lB = new List<B>();
lb.Add(new B());
lb.Add(new B());
lb.Add(new B());
lA.Add(lB);

What I want to do is build a new list of type 'b' from lA where a property on 'b' is true.

Any help with this would be greatly appreciated,

Mark


Try this one

lA.SelectMany(a => a.PropertyOfListOfBType).Where(b => b.SomeProperty).ToList()
0

精彩评论

暂无评论...
验证码 换一张
取 消