Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting keys from a Lookup

How do I get the collection of keys from a Lookup<> I created through the .ToLookup() method?

I have a lookup which maps int-values to groups of instances of a custom class. I need a collection of all the int keys that the lookup contains. Any way to do this, or do I have to collect and save them separately?

like image 751
magnattic Avatar asked Apr 26 '11 14:04

magnattic


1 Answers

You can iterate through the set of key-item groups and read off the keys, e.g.

var keys = myLookup.Select(g => g.Key).ToList(); 
like image 179
Rup Avatar answered Sep 28 '22 03:09

Rup