使用for循环(0-12)进行初始化时不会发生此问题myarr[i] = new double[12];为什么会这样?解决方案其他答案已解释了该问题.解决方案是在每次迭代中创建一个新数组,例如double[][] myarr = Enumerable.Range(0, 13) .Select(ignored => new double[12]) .ToArray();I initialized an Array asDouble[][] myarr = Enumerable.Repeat(new double[12], 13).ToArray();Then in a loop i am incrementing values like myarr[0][0]++; This causes all values like myarr[1][0], myarr[2][0], myarr[3][0] ..... myarr[12][0] to increment by one.This problem is not occurring when using a for loop (0-12) i am initializing likemyarr[i] = new double[12];Why is this so? 解决方案 Other answers have explained the problem. The solution is to create a new array on each iteration, e.g.double[][] myarr = Enumerable.Range(0, 13) .Select(ignored => new double[12]) .ToArray(); 这篇关于Enumerable.Repeat有一些内存问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-23 04:55