Reputation: 12755
Let's say I have a list called list1
. This list1
contains another list, called list2
. Now I want to check if list2
in list1
contains certain elements and return another list.
list3 = list1.list2.Where(p => p.something == 1)
Something like that?
Upvotes: 0
Views: 1142
Reputation: 43523
This solution will return conditioned items in the inner list.
var result = list.SelectMany(l => l.InnerList)
.Where(p => p.something == 1);
If you want to get items in the outer list which meets the condition, use:
var another = list.Where(l => l.InnerList.Any(p => p.something == 1));
Upvotes: 2