How do you sort a dictionary by value?

前端 未结 19 2761
误落风尘
误落风尘 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 03:57

    Sort and print:

    var items = from pair in players_Dic
                    orderby pair.Value descending
                    select pair;
    
    // Display results.
    foreach (KeyValuePair pair in items)
    {
        Debug.Log(pair.Key + " - " + pair.Value);
    }
    

    Change descending to acending to change sort order

提交回复
热议问题