![](/img/trans.png)
[英](jagged array) Array of an Array: automatically create in while loop, how to initialize?
[英]IndexOutOfRangeException when Using loop to create jagged array
當試圖使用循環來創建一個鋸齒狀數組時,但是當i和j為0時,我會得到一個IndexOutOfRangeException。這是代碼
double[,][] coords = new double[,][] { };
for (int i = 0; i <= p; i++)
{
for (int j = 0; j <= q; j++)
{
coords[i, j] = new double[4] { (4 things in here) };
}
}
我已經讀過這個: http : //www.daniweb.com/software-development/java/threads/360615但不知道如何應用它。
解決方案:改為“double [,] [] coords = new double [,] [] {};” 改為“ double [,] []坐標=新double [p,q] [];” 謝謝!
你需要實例化你的數組大小,從你的代碼我認為這將是正確的大小。
double[,][] coords = new double[p+1,q+1][];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.