C# – How to sort a dictionary

Dictionaries are unordered data structures. Key/value pairs aren’t stored in sorted order. When you want the Dictionary in sorted order, there are two simple options: I’ll show both options. Sort Dictionary with OrderBy() Use OrderBy() (from System.Linq) to sort the Dictionary by key or value. It returns the Dictionary’s KeyValuePairs in ascending sorted order. I’ll … Read more