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

本文介绍了一种通过使用VoltageCount类存储电压值及其对应数量的方法,并利用字典(Dictionary&lt;Point,VoltageCount&gt;)来关联坐标点与电压统计数据。通过对字典进行排序,实现了按电压值数量降序排列的功能,便于进一步的数据分析与图表展示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


//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);



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值