Good way to get the key of the highest value of a Dictionary in C#
- by Arda Xi
I'm trying to get the key of the maximum value in the Dictionary<double, string> results.
This is what I have so far:
double max = results.Max(kvp => kvp.Value);
return results.Where(kvp => kvp.Value == max).Select(kvp => kvp.Key).First();
However, since this seems a little inefficient, I was wondering whether there was a better way to do this.