对复杂字典Dictionary<T1,T2>排序问题

来源:互联网 发布:龙虎山的旅游收入数据 编辑:程序博客网 时间:2024/04/30 11:12


//VoltageCount类(电压值对应的数量):
    public class VoltageCount
    {
        public Double Voltage { get; set; } //电压值
        public int CountV { get; set; } //电压值对应的数量
        public VoltageCount()
        {
        }

        public VoltageCount(Double voltage, int countV)
        {
            this.Voltage = voltage;
            this.CountV = countV;
        }
    }

Dictionary<Point, VoltageCount>是将坐标点(绘制图像时使用)与VoltageCount数据对应的字典,目的用来在绘图对象(Graphics)中绘制电压值-数量的对应图像(如图中右侧部分)。

由于同时需要按数量大小进行排序,以便输出表格(如图中左边两表格,分别按数量降序排列),所以这里涉及字典排序问题。

            Dictionary<Point, VoltageCount> result = new Dictionary<Point, VoltageCount>();

                for (int i = 0; i <= 4; i++)
                {
                    result.Add(listHeatPoints[i], dictionaryPointVoltageCount[listHeatPoints[i]]);

                }

//排序

            Dictionary<Point, VoltageCount> dicSort = result.OrderByDescending(s => s.Value.CountV)

                .ToDictionary(pair => pair.Key, pair => pair.Value);



原创粉丝点击