這是我的變量string[,] table = new string[104, 6];int moveRow = 1;int moveCol = 1;int sum1 = 0;int sum2 = 0;int rowIndex1 = 1;int rowIndex2 = 0;int firstTableRow = 1;int firstTableCol = 1;int secondTableRow = 1;int secondTableCol = 0;int thirdTableRow = 0;int thirdTableCol = 1;int fourthTableRow = 0;int fourthTableCol = 0;int counterNextRow = 0;現(xiàn)在它給了我(只為我)一個(gè)奇怪的Array index is out of range地方if (moveRow > 1){ firstTableCol += 1; secondTableCol += 1; thirdTableCol += 1; fourthTableCol += 1; //r1 = table[2,1] r2 = table[2,0] r3 = table[1,1] r4 = table[1,0] string d1 = table[firstTableRow, firstTableCol]; //<------- HERE ITS GIVING ME THE ERROR string d2 = table[secondTableRow, secondTableCol]; string d3 = table[thirdTableRow, thirdTableCol]; string d4 = table[fourthTableRow, fourthTableCol]; moveRow += 1;}由于那個(gè)錯(cuò)誤,我一直被困在這里,我不知道為什么它會(huì)給我一個(gè)Array index is out of range錯(cuò)誤。我那里沒有任何負(fù)數(shù),所以據(jù)說我不會(huì)遇到那種錯(cuò)誤。有人可以指出我。
3 回答

POPMUISE
TA貢獻(xiàn)1765條經(jīng)驗(yàn) 獲得超5個(gè)贊
數(shù)組索引范圍必須是 0 到 103 而不是 1 到 104。它可能會(huì)解決您的問題。
int moveRow = 0; int moveCol = 0;

江戶川亂折騰
TA貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超5個(gè)贊
嗯,我忘了檢查我的變量的長(zhǎng)度到我正在使用的維度。所以通過這樣做,例如我的變量,rowIndex1我需要像這樣檢查它
if(rowIndex1 + 1 < table.GetLength(0)){
rowIndex++;
}
謝謝你們的時(shí)間。
- 3 回答
- 0 關(guān)注
- 172 瀏覽
添加回答
舉報(bào)
0/150
提交
取消