<分区>
我有一个字典,我想找到具有最高值的键。
例如如果我有
Key | Value
a | 1
b | 2
c | 3
我希望返回 c。
我现在有这个,但它只搜索最高值,我不确定如何返回 key 。
var max = occurrences.Max(x => x.Value);
标签 c# dictionary
<分区>
我有一个字典,我想找到具有最高值的键。
例如如果我有
Key | Value
a | 1
b | 2
c | 3
我希望返回 c。
我现在有这个,但它只搜索最高值,我不确定如何返回 key 。
var max = occurrences.Max(x => x.Value);
最佳答案
var maxKey = occurrences.OrderByDescending(x => x.Value).First().Key;
关于c# - 如何在 C# 字典中找到具有最高值的键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43930581/