我有一个二维数组。例如,它就像:
{{{0, 0, 1}, {1, 0, 0}}
{{0, 0, 3}, {2, 1, 2}, {2, 2, 1}, {3, 0, 0}}
{{0, 0, 7}, {3, 2, 6}, {6, 2, 3}, {6, 3, 2}, {7, 0, 0}}}
但如果我写
int [,][] arrays={{{0, 0, 1}, {1, 0, 0}}
{{0, 0, 3}, {2, 1, 2}, {2, 2, 1}, {3, 0, 0}}
{{0, 0, 7}, {3, 2, 6}, {6, 2, 3}, {6, 3, 2}, {7, 0, 0}}};
编译器会抱怨“;预期”。
如果我写
int [,][] arrays={new int[,] {{0, 0, 1}, {1, 0, 0}}
new int[,] {{0, 0, 3}, {2, 1, 2}, {2, 2, 1}, {3, 0, 0}}
new int[,] {{0, 0, 7}, {3, 2, 6}, {6, 2, 3}, {6, 3, 2}, {7, 0, 0}}};
编译器会抱怨
“需要一个嵌套数组初始值设定项”。
那么为什么会发生这种情况,正确的初始化方式是什么?