更新时间:2023-11-23 16:04:34
下面就给您根据您OrderedDictionary排序的字典。
Following will give you a sorted dictionary based on your OrderedDictionary.
var sortedDictionary= od.Cast<DictionaryEntry>()
.OrderBy(r=> r.Value)
.ToDictionary(c=> c.Key, d=> d.Value);
输出:
foreach (var entry in sortedDictionary)
Console.WriteLine("Key: {0} Value: {1}", entry.Key, entry.Value);
Key: a3 Value: 2
Key: a1 Value: 3
Key: a4 Value: 4
Key: a2 Value: 5