How to find the minimum key in the dictionary

I declare the dictionary as follows:

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

And I used the following:

touchDictionary[touchID]= touchObject;

So, touchDictionary will save the key from touchID. Now I am trying to find the minimum key using a dictionary, but I do not know how to do this. Any suggestions?

Regard, C. Porawat

+5
source share
3 answers

A dictionary has a Keys property that allows you to list keys in a dictionary. You can use the Min Linq extension methods to get the minimum key as follows:

int minimumKey = touchDictionary.Keys.Min();
+17
source

Something like that touchDictionary.Keys.Min(). Just make sure you import the namespace System.Linq.

0
source

SO:

?

0

All Articles