【发布时间】:2015-12-12 04:33:23
【问题描述】:
Dictionary<double, Tuple<int,int>> dictionary = new Dictionary<double, Tuple<int,int>>();
for (int i = 0; i < x.Length; i++)
for (int j = i+1; j < x.Length; j++)
{
double weight = Math.Round(Math.Sqrt(Math.Pow((x[i] - x[j]), 2) + Math.Pow((y[i] - y[j]), 2)), 2);
string edges = i + "-" + j + "-" + weight;
listBox1.Items.Add(edges);
Tuple<int, int> tuple = new Tuple<int, int>(i, j);
dictionary.Add(weight, tuple);
}
var list = dictionary.Keys.ToList();
list.Sort();
foreach (var key in list)
{
string a = dictionary[key].Item1 + "--" + dictionary[key].Item2 + "--> " + key.ToString();
listBox2.Items.Add(a);
}
我正在尝试将一些值存储在字典中。但是在 for 循环中突然中断了不完整的值。没有错误信息。 当我注释掉“dictionary.Add(weight, tuple);”列表框正在显示我想要的所有数据。
【问题讨论】:
-
x到底是什么? -
它是所有x点的x值的x-y坐标系数组
-
当您注释掉
dictionary.Add(weight, tuple);时,列表框怎么可能显示您想要的所有数据?列表框正在从字典中填充,如果您发表该评论,该字典将为空。 -
for 循环中的listbox1 正在填充所有数据。
标签: c# loops for-loop dictionary break