Just a Friday morning heads up. Last night I had to search through a
collection of object collections, and knew I wanted a "flatten" operator
like Mathematica and other languages have, but couldn't find one. I started
coding LINQ Aggregate with Concat and creating a LISP-like clever mess. I
thought this was a bit silly so I flipped through one of my books and
suspected that SelectMany might be what I want. The description of the
operator was a bit misleading (and so is the name), but it turns out that
SelectMany is actually a "Flatten" in disguise. So you can simply do this:

 

ParentColl.SelectMany(p => p.ChildColl).Where(c => c.Type == "Foo");

 

Greg

Reply via email to