日期:2014-05-16  浏览次数:21322 次

c# 字典的查找及其排序问题
Dictionary<PointF, List<float>> pointDatas
我想根据这里的PointF 中的X、Y 分别除以 a,b 两个数找到 商相同的数据 再按他们的余数 来排序,请问这个怎么操作?
------解决方案--------------------
Dictionary<Point, List<float>> pointDatas = new Dictionary<Point, List<float>>()
            {
                {new Point(10,20),new List<float>(){1.2f,1.3f}},
                {new Point(40,60),new List<float>(){1.2f,1.3f}},
                {new Point(15,20),new List<float>(){1.2f,1.3f}},
                {new Point(20,30),new List<float>(){1.2f,1.3f}}
            };
            //假设a,b
            int a = 2, b = 3;
            var result = pointDatas.Where(x=>x.Key.X/a==x.Key.Y/b).OrderBy(x=>x.Key.X%x.Key.Y);//余数升序排列
            //var result = pointDatas.Where(x => x.Key.X / a == x.Key.Y / b).OrderByDescending(x => x.Key.X % x.Key.Y);//余数降序排列
            /*
             * + [0] {[{X=20,Y=30}, System.Collections.Generic.List`1[System.Single]]} System.Collections.Generic.KeyValuePair<System.Drawing.Point,System.Collections.Generic.List<float>>
+ [1] {[{X=40,Y=60}, System.Collections.Generic.List`1[System.Single]]} System.Collections.Generic.KeyValuePair<System.Drawing.Point,System.Collections.Generic.List<float>>

             */

------解决方案--------------------
引用:
Quote: 引用:

Dictionary<Point, List<float>> pointDatas = new Dictionary<Point, List<float>>()
            {
                {new Point(10,20),new List<float>(){1.2f,1.3f}},
                {new Point(40,60),new List<float>(){1.2f,1.3f}},
                {new Point(15,20),new List<float>(){1.2f,1.3f}},
                {new Point(20,30),new List<float>(){1.2f,1.3f}}
            };
            //假设a,b
            int a = 2, b = 3;
    &nb