原文:
对复杂字典Dictionary<T1,T2>排序问题
{
result.Add(listHeatPoints[i], dictionaryPointVoltageCount[listHeatPoints[i]]);
//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]]);
}
//排序
.ToDictionary(pair => pair.Key, pair => pair.Value);