How do you sort a dictionary by value?

前端 未结 19 2359
误落风尘
误落风尘 2020-11-22 03:51

I often have to sort a dictionary, consisting of keys & values, by value. For example, I have a hash of words and respective frequencies, that I want to order by frequen

相关标签:
19条回答
  • 2020-11-22 04:21

    You can sort the Dictionary by value and get the result in dictionary using the code below:

    Dictionary <<string, string>> ShareUserNewCopy = 
           ShareUserCopy.OrderBy(x => x.Value).ToDictionary(pair => pair.Key,
                                                            pair => pair.Value);                                          
    
    0 讨论(0)
提交回复
热议问题