Good way to get the key of the highest value of a Dictionary in C#

Posted by Arda Xi on Stack Overflow See other posts from Stack Overflow or by Arda Xi
Published on 2010-05-10T19:16:15Z Indexed on 2010/05/10 19:24 UTC
Read the original article Hit count: 406

Filed under:
|
|
|

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.

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ