如何词典者皆排序 [英] How to sort a dictionary by key
本文介绍了如何词典者皆排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的字典词典<串,点>
的关键是C1,C3,C2,T1,T4,T2我想排序它们来为c1,C2,C3,T1,T2,T3
the Key is c1,c3,c2,t1,,t4,t2 I want to sort them to be c1,c2,c3,t1,t2,t3
我试图用对它进行排序
Input.OrderBy(key => key.Key );
,但它不工作
but it doesn't work
任何想法如何解决
推荐答案
确定检查这个它应该工作
ok check this it should work
var r = new Dictionary<string, Point>();
r.Add("c3", new Point(0, 0));
r.Add("c1", new Point(0, 0));
r.Add("t3", new Point(0, 0));
r.Add("c4", new Point(0, 0));
r.Add("c2", new Point(0, 0));
r.Add("t1", new Point(0, 0));
r.Add("t2", new Point(0, 0));
var l = r.OrderBy(key => key.Key);
var dic = l.ToDictionary((keyItem) => keyItem.Key, (valueItem) => valueItem.Value);
foreach (var item in dic)
{
Console.WriteLine(item.Key);
}
Console.ReadLine();
这篇关于如何词典者皆排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文