Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find minimum key in dictionary

Tags:

c#

dictionary

I declare dictionary as following:

private Dictionary<int, touchInformation> touchDictionary = new Dictionary<int, touchInformation>();

And I used as following:

touchDictionary[touchID] = touchObject;

So, the touchDictionary will keep the key from touchID. Now, I try to find the minimum key using dictionary but I don't know how to do. Have any suggestion?

Regard, C.Porawat

like image 843
Porawat Chimcherdsin Avatar asked Jan 26 '11 09:01

Porawat Chimcherdsin


1 Answers

Dictionary has a Keys property which allows you to enumerate the keys within the dictionary. You can use the Min Linq extension methods to get the minimum key as follows:

int minimumKey = touchDictionary.Keys.Min();
like image 105
ColinE Avatar answered Oct 19 '22 22:10

ColinE