using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
// Changed from *int[,] matrix = new int[2, 2];*
int[,] matrix = new int[3, 3];
// Still getting error with "[3,3]"
matrix[0, 0] = 1;
matrix[0, 1] = 2;
matrix[0, 2] = 3;
matrix[1, 0] = 4;
matrix[1, 1] = 5;
matrix[1, 2] = 6;
matrix[2, 0] = 7;
matrix[2, 1] = 8;
matrix[2, 2] = 9;
Console.Write(matrix[0, 2]);
Console.ReadKey();
}
}
}
這是通過命令行執行的基本程序。多維數組:「索引超出了數組的範圍。」
在運行,而不是顯示存儲在數組中的數字「3」 [0,2],我帶有此錯誤:
System.IndexOutOfRangeException:「指數陣列的邊界之外「。
它應該是'new int [3,3];',這裏的數字表示每個維度的長度。 –
你可能想看看這個:https://stackoverflow.com/questions/3814145/how-can-i-declare-a-two-dimensional-string-array –
我正在閱讀的書給我的印象是陣列從零開始向上計數,因此0,1,2將計爲「三」。 – Jojo