我有一个Dictionary<Point, int> MyDic,Point类定义如下:
public class Point
{
public double X { get; set; }
public double Y { get; set; }
}如何使用MyDic根据其Key对LINQ进行排序?我想按X订,然后用Y订。
例如,如果我的字典如下所示:
Key (Point (X,Y)) Value (int)
--------------------------------------
(8,9) 6
(5,4) 3
(1,4) 2
(11,14) 1排序后会是这样的:
Key (Point (X,Y)) Value (int)
--------------------------------------
(1,4) 2
(5,4) 3
(8,9) 6
(11,14) 1发布于 2014-05-31 22:33:09
OrderBy和ThenBy应该为您做好以下工作:
MyDic.OrderBy(x => x.Key.X)
.ThenBy(x => x.Key.Y)
.ToDictionary(x => x.Key, x => x.Value)https://stackoverflow.com/questions/23975040
复制相似问题