tags:

views:

70

answers:

1

Hi,

I have a generic list of type 'a' which contains a generic list 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

+2  A: 

Try this one

lA.SelectMany(a => a.PropertyOfListOfBType).Where(b => b.SomeProperty).ToList()
Yury Tarabanko
lA.SelectMany(a => a.Where(b => b.SomeProperty)).ToList()
markpirvine
Yep, that's better! :)
Yury Tarabanko