亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

無法弄清楚這個“數組索引超出范圍”錯誤

無法弄清楚這個“數組索引超出范圍”錯誤

C#
翻閱古今 2021-06-29 03:27:13
這是我的變量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;現在它給了我(只為我)一個奇怪的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;}由于那個錯誤,我一直被困在這里,我不知道為什么它會給我一個Array index is out of range錯誤。我那里沒有任何負數,所以據說我不會遇到那種錯誤。有人可以指出我。
查看完整描述

3 回答

?
POPMUISE

TA貢獻1765條經驗 獲得超5個贊

數組索引范圍必須是 0 到 103 而不是 1 到 104。它可能會解決您的問題。

int moveRow = 0;
int moveCol = 0;


查看完整回答
反對 回復 2021-07-03
?
江戶川亂折騰

TA貢獻1851條經驗 獲得超5個贊

嗯,我忘了檢查我的變量的長度到我正在使用的維度。所以通過這樣做,例如我的變量,rowIndex1我需要像這樣檢查它


if(rowIndex1 + 1 < table.GetLength(0)){

    rowIndex++;

}

謝謝你們的時間。


查看完整回答
反對 回復 2021-07-03
  • 3 回答
  • 0 關注
  • 175 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號