score:3

Accepted answer
var mylistoftypea = new list<typea>();
// ...
var citems = 
    from a in mylistoftypea
    from b in a.mylistoftypeb
    from c in a.mylistoftypec
    where c.someinteger > 100
    select c;

the above is equivalent to calling the selectmany linq 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):

var citems = 
    mylistoftypea.selectmany( a => a.mylistoftypeb )
                 .selectmany( b => b.mylistoftypec )
                 .where( c => c.somevalue > 200 );

score:2

you need to navigate all sublists, and that what from can do for you.

var ta = new typea();

var alltypecsthatsatisfymycondition = 
    from tb in ta.mylistoftypeb                     // this will iterate to each item in the list
    from tc in tb.mylistoftypec                     // this will iterate to each item in the *sublist*
    where tc.someinteger > 100          // condition could be anything; filter the results
    select tc;                                      // when you select, you tell your iterator to yield return that value to the caller.

return alltypecsthatsatisfymycondition.tolist();    // to list will force the linq to execute and iterate over all items in the lists, and add then to a list, effectively converting the returned items to a list.

score:3

you can do it the following way using linq:

    var mylistoftypea = new list<typea>();

    // fill your list here

    var typecs = from typea in mylistoftypea
                 from typeb in typea.mylistoftypeb
                 from typec in typeb.mylistoftypec
                 where typec.someinteger > 100
                 select typec;

score:4

something like this is what you're looking for i think:

var result = mylistoftypea.selectmany(b => b.mylistoftypeb.selectmany(c => c.mylistoftypec.select(x => x.someinteger > 100))).tolist();

Related Query

More Query from same tag