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