0

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

0

1 Answer 1

2

Try this one

lA.SelectMany(a => a.PropertyOfListOfBType).Where(b => b.SomeProperty).ToList()
Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.