Я попробовал этот код:
Dictionary<string, string> dict = new Dictionary<string,string>();
dict.Add("3", "three");
dict.Add("1", "one");
dict.Add("2", "two");
var sortedDict = (from entry in dict orderby entry.Key ascending select entry);
foreach (var k in sortedDict)
{
Console.WriteLine("key:{0}, val={1} ", k.Key, k.Value);
}
Это работает, но sortedDict не словарь.Я решил это:
sortedDict = (from entry in dict orderby entry.Key ascending select entry)
.ToDictionary(x => x.Key, x => x.Value);