开发者

Getting keys from a Lookup

开发者 https://www.devze.com 2023-03-01 00:09 出处:网络
How do I get the collection of keys from a Loo开发者_JAVA技巧kup<> I created through the .ToLookup() method?

How do I get the collection of keys from a Loo开发者_JAVA技巧kup<> 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?


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();


One fast way:

var myKeys = myLookup.Select(l=>l.Key);
0

精彩评论

暂无评论...
验证码 换一张
取 消