You can use SortedDictionary for this, which will do key sorting for you. In your case, SortedDictionary<string, int> will work:
SortedDictionary<string, int> dict = new SortedDictionary<string, int>(); dict.Add("Exchange C", 200); dict.Add("Exchange A", 200); dict.Add("Exchange V", 100); foreach (var kvp in dict) { Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value); }
Output:
Key = Exchange A, Value = 200 Key = Exchange C, Value = 200 Key = Exchange V, Value = 100
source share