I have a List<List<List<Foo>>> and I would like to flatten this to List<new {Foo, Ndx}> where Ndx is the index from the outermost List. For example, if I had something like:
new List(){
new List(){
new List(){ new Foo("a"), new Foo("b")},
new List(){ new Foo("c")}},
new List(){
new List(){ new Foo("x"), new Foo("y")}}}
I might end up with Ndx of 0 for “a”, “b”, & “c” and 1 for “x” & “y”. Someone have a LINQ solution?
Bit fiddly, but you can do it like this:
A compilable version is:
EDIT: As @sll points out, this solution requires .NET 4 due to the use of
Tuple. It wouldn’t be too hard to adapt though if necessary.