在C#中使用类似于Java的多维数组

Nik*_*nis 1 c# java arrays porting multidimensional-array

在Java中我们可以这样做:

bool[][] something = new bool[5][10];

// Then, we can do this, since indexes do not refer to null instances:
something [3][7] = true;
Run Code Online (Sandbox Code Playgroud)

但是,在C#中似乎没有编译.在C#中有相同的方法吗?

vcs*_*nes 7

语法略有不同:

bool[,] something = new bool[5,10];
// Then, we can do this, since indexes do not refer to null instances:
something [3,7] = true;
Run Code Online (Sandbox Code Playgroud)

或者,如果您使用的是C#3.0+,则可以略微简化声明:

//Doesn't work for fields.
var something = new bool[5,10];
Run Code Online (Sandbox Code Playgroud)

那是一个多维数组.您可以参考MSDN以获取更多信息.