按键排序字典?

由于WP7不支持
SortedDictionary
,我需要按键排序字典。我怎样才能做到漂亮,简单和最佳?     
已邀请:
此堆栈溢出问题包括使用LINQ的解决方案。 你如何按价值排序字典?     
我试过这段代码:
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); 
    

要回复问题请先登录注册