How to get MAX value from Dictionary?

前端 未结 8 2156
独厮守ぢ
独厮守ぢ 2020-12-30 19:16

I have

Dictionary d = new Dictionary();

How I can get an Guid which has MAX

相关标签:
8条回答
  • 2020-12-30 20:02

    Guid implements IComparable, so:

    d.Keys.Max()
    

    Also it is not clear why one would want to do so...

    0 讨论(0)
  • 2020-12-30 20:07

    The accepted answer didn't work for me. The following code (using MoreLinq) did the job though:

    var fooDict = new Dictionary<string, int>();
    var keyForBiggest = fooDict.MaxBy(kvp => kvp.Value).Key;
    var biggestInt = fooDict[keyForBiggest];
    
    0 讨论(0)
提交回复
热议问题