Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to flatten a .Net ILookup<TKey, TElement> into a List<TElement>?

Tags:

.net

ilookup

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
like image 255
Joomala Avatar asked Feb 24 '10 02:02

Joomala


1 Answers

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

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

like image 136
Tinister Avatar answered Nov 19 '22 23:11

Tinister