16

Is there a quick way to get a flattened List<TElement> from an ILookup<TKey, TElement> that was created from the IEnumerable<TElement> extension?


Updated with example

List<int> list = new List<int>();
var lookup = list.ToLookup(key => key);
list = lookup.?? // How to convert the lookup back to the list
Joomala
  • 233
  • 2
  • 6

2 Answers2

31
lookup.SelectMany( x => x ).ToList()

The transformation to ILookup and back again will have most likely changed the order, however.

Tinister
  • 11,097
  • 6
  • 35
  • 36
0

Not sure if this is what you are after. For Dictionary<> to List<>

List<TElement> list iLookUp.Values.ToList<TElement>();

from List<> to Dictionary<>

var dict = list.Cast<TElement>().ToDictionary(t => t.Id, t => t.Description);
Asad
  • 21,468
  • 17
  • 69
  • 94