مرتب سازی دیکشنری
نویسنده: علی یگانه مقدم
تاریخ: ۱۳۹۷/۰۸/۲۴ ۱۱:۴
آدرس: www.dntips.ir
// Create dictionary and add five keys and values.
var dictionary = new Dictionary<string, int>();
dictionary.Add("car", 2);
dictionary.Add("apple", 1);
dictionary.Add("zebra", 0);
dictionary.Add("mouse", 5);
dictionary.Add("year", 3);
// Acquire keys and sort them.
var list = dictionary.Keys.ToList();
list.Sort();
// Loop through keys.
foreach (var key in list)
{
Console.WriteLine("{0}: {1}", key, dictionary[key]);
}