Accepted answer

here's the obligatory method form.

return parents
  .selectmany(p => p.children);

and for two levels:

return oldies
  .selectmany(grand => grand.children)
  .selectmany(parent => parent.children);


this will work:

public ienumerable<child> getallchildren(ienumerable<parent> parents)
    return from parent in parents
           from child in parent.children
           select child;

and then this:

public ienumerable<child> getallchildren(ienumerable<grandparent> nanas)
    return from papa in nanas
           from parent in papa.children
           from child in parent.children
           select child;

note, in this example i'm not actually returning a list, i'm returning an ienumerable data source that until you start to foreach over it, or similar, won't actually do any processing.

if you need to return a list, modify each return statement as follows:

    return (from .....
            select child).tolist();

Related Query

More Query from same tag