1

What is the best way to convert IEnumerable<IGrouping<T,K>> to IEnumerable<K> ?

It seems this way will work:

myEnumerable = myEnumerableOfGroups
    .Select( group => group.AsEnumerable)
    .Aggregate((enumA, enumB) => enumA.Concat(enumB));

is there a more efficient way to do it ?

MichaelB
  • 1,332
  • 1
  • 15
  • 29

1 Answers1

1

This should do it:

myEnumerable = myEnumerableOfGroups.SelectMany(group => group);

The MSDN page for this overload of SelectMany is here.

Ani
  • 111,048
  • 26
  • 262
  • 307
  • Wow, that was fast :), Thanks – MichaelB Jun 09 '14 at 15:01
  • 1
    @MichaelB It's a shame that the fastest reaction to such a question is "rep!" not "maybe it's a duplicate". – Rawling Jun 09 '14 at 15:02
  • 2
    @MichaelB That tells you just how little research you did before asking your question, not how skilled of a poster any of the people who answered the question were. – Servy Jun 09 '14 at 15:02