I have 3 types of objects, TypeA,TypeB,TypeC. TypeA has a list of TypeB and TypeB has a list of TypeC, and TypeC has some variables I wanna keep track of
Class TypeA
{
List<TypeB> MyListOfTypeB;
//...
}
Class TypeB
{
List<TypeC> MyListOfTypeC;
//...
}
Class TypeC
{
int SomeInteger;
//...
}
Given a List<TypeA> MyListOfTypeA, I wanna look for all TypeC Objects which fulfill a certain condition, such as, SomeInteger > 100. Other than nesting for/foreach loops, what is the Linq way to do this?
The above is equivalent to calling the
SelectManyLINQ function, but in my opinion it is significantly cleaner and easier to read.Doing it with LINQ functions (as already suggested by Dmitry, though with some modifications):