Q: Convert Flat list to Relational List I have a "flat" array of data in struct Foo which has members parent and child:
struct Foo { string parent, string child }

They might have data like so:
"parent1", "child1"
"parent1", "child2"
"parent2", "child3"
"parent2", "child4"

I want to coerce them to a "relational" struct:
struct Bar { string parent, string[] children }

and have the filled like so:
"parent1"
    "child1"
    "child2"
"parent2"
    "child3"
    "child4"

I can do it via loops just fine, but looking to improve my linq skills... I'm sure there must be a way?  Thanks (4.5 framework)

A: Use GroupBy:
array.GroupBy(f => f.parent)
    .Select(g => new Bar { parent = g.Key, children = g.Select(f => f.child).ToArray() })
    .ToArray();

