The best resources for developers

How do you sort a dictionary by value?

using System.Linq.Enumerable;
List<KeyValuePair<string, string>> myList = aDictionary.ToList();

    delegate(KeyValuePair<string, string> pair1,
    KeyValuePair<string, string> pair2)
        return pair1.Value.CompareTo(pair2.Value);
var myList = aDictionary.ToList();

myList.Sort((pair1,pair2) => pair1.Value.CompareTo(pair2.Value));

Tags: .net c# sorting dictionary

Source: By Kalid as answer to the question

This code snippet was collected from stackoverflow, and is licensed under CC BY-SA 3.0

Related code-snippets: