对于:
1 2 3 | Tuple <double[], double[]> output = crifanDFT.DFT( input ); double[] outputList1 = output.Item1; double[] outputList2 = output.Item2; |
对于变量值,其实debug是能看到:

想要去打印出两个浮点数数组的值
用:
1 2 | Console.WriteLine(outputList1.ToString()); Console.WriteLine(outputList2.ToString()); |
结果是:
1 2 | System.Double[] System.Double[] |
真垃圾
但是想要打印出来:
然后想要for循环,打印列表1,然后用当期index,去获取到列表2的值
这样成对的值,就可以方便对比查看了
搜
c# for loop index
竟然for循环 获取index 这么麻烦
没有Python的enumerate方便
试了
1 2 3 | foreach (var item in Model.Select((value, i) = > new { i, value })){ var value = item.value; var index = item.i;} |
无法识别Model,放弃。
1 | foreach (var (item, index) in outputList1.WithIndex()) |
结果:
CS1061“double[]”未包含“WithIndex”的定义,并且找不到可接受第一个“double[]”类型参数的可访问扩展方法“WithIndex”(是否缺少 using 指令或程序集引用?)
【总结】
C#中,for循环中,想要获取当前的index索引值:
算了,还是用最原始的index自己去自增吧:
1 2 3 4 5 6 | int curIdx = 0; foreach (double curItem1Value in outputList1) { ... curIdx++; } |
转载请注明:在路上 » 【已解决】C#中循环打印列表变量及当期索引值