Answers for "how to sort a dictionary by value in c#"

C#
1

how to sort a dictionary by value in c#

Dictionary<string, int> myDict = new Dictionary<string, int>();
myDict.Add("one", 1);
myDict.Add("four", 4);
myDict.Add("two", 2);
myDict.Add("three", 3);

var sortedDict = from entry in myDict orderby entry.Value ascending select entry;
Posted by: Guest on August-14-2021
0

how to sort a dictionary by value in c#

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

myList.Sort(
    delegate(KeyValuePair<string, string> pair1,
    KeyValuePair<string, string> pair2)
    {
        return pair1.Value.CompareTo(pair2.Value);
    }
);
Posted by: Guest on July-24-2021

Code answers related to "how to sort a dictionary by value in c#"

C# Answers by Framework

Browse Popular Code Answers by Language