【发布时间】:2020-11-04 22:59:20
【问题描述】:
我正在尝试将列表应用于 for 循环。 sumlist[sz] 返回许多数字,if (sumOfVolumes4 >= sumlist[sz]) 应该测试每个数字,但只测试最后一个数字而不测试其他数字。 foundIndex 应该返回多个答案,但只返回一个。
for (double d = 1.61D; d < 4.24; d+= 0.01D) {
List<double> sumlist = new List<double>() {d};
for(int sz = 0; sz < sumlist.Count; sz++) {
sumlist[sz] = (volumeValue /= sumlist[sz]);
for(int barIndex = index; barIndex >= ChartBars.FromIndex; barIndex--) {
sumOfVolumes4 += Bars.GetVolume(barIndex);
if (sumOfVolumes4 >= sumlist[sz]) {
foundIndex = barIndex;
break;
}
}
}
}
【问题讨论】:
-
我不懂打印(sumlist);我得到的值与 1.61 和 4.24 之间的差值一样多。
-
您可能需要更好地解释一下。我不太明白这段代码背后的目标。必须有一种不同于 3 个 for 循环的方式来进行。也许是一些 Linq 或 Foreach?
-
此外,sumlist 始终包含 1 个值,因为您在循环开始时分配了它。所以第二个循环只迭代一次。一个想法是最终执行第一个 forLoop 以将所有值添加到 sumList。然后在 sumlist 上进行 foreach
-
第一个 for 循环枚举 1.61 到 4.24,第二个应用列表将 5000 除以 1.61、1.62 等直到 4.24 在第三个 for 循环中,我有 5000/1.61 = 3105、5000/1.62, 3086 等,每个答案都经过测试,以使用 if 语句找到 barIndex 等于 3105、3086 等。foundIndex 应枚举所有满足条件的 barIndex。