锯齿状阵列数组

时间:2015-07-06 14:48:07

标签: c# jagged-arrays

我有几个像这样的锯齿状数组:

int[][] map0 = {
                    new int[]{1 ,2 ,1 ,2 ,1 ,2 ,1 ,17 ,1 ,2 ,12 ,13 ,1 ,2 ,1 ,2 ,8 ,9 ,10 ,11 ,1 ,2 ,1 ,2 ,1 ,2 ,1 ,2 ,1 ,2 },
                    new int[]{29 ,30 ,29 ,30 ,29 ,30 ,29 ,30 ,29 ,30 ,29 ,30 ,29 ,30 ,29 ,30 ,29 ,30 ,29 ,30 ,29 ,30 ,29 ,30 ,29 ,30 ,29 ,30 ,29 ,30 },
                    new int[]{31 ,32 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,78 ,98 ,99 ,79 ,0 ,0 ,0 ,0 ,0 ,98 ,99 ,0 ,0 ,0 ,0 ,0 ,0 },
                    new int[]{31 ,37 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,95 ,96 ,96 ,96 ,96 ,97 ,0 ,0 ,0 ,0 ,100 ,101 ,0 ,0 ,0 ,0 ,0 ,0 },
                    new int[]{31 ,38 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,102 ,103 ,0 ,0 ,0 ,0 ,0 ,0 },
                    new int[]{31 ,32 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 },
                    new int[]{31 ,32 ,66 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 },
                    new int[]{35 ,36 ,67 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0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 ,0 ,0 ,108 ,109 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 },
                    new int[]{31 ,32 ,0 ,0 ,106 ,0 ,0 ,0 ,110 ,111 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,110 ,111 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 },
                    new int[]{31 ,32 ,0 ,0 ,107 ,0 ,0 ,0 ,56 ,57 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,56 ,57 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 },
                    new int[]{26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 },
                    new int[]{27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 },
                    };

现在我想要另一个数组来保存这些数组,这样我就可以从中选择一个随机的锯齿状数组 我做了:

int[][][] mapArray = {map0,map1..}; 

但它给我一个编译错误,说An object reference is required for the non static field, method, or property 'map0'
int[int[][]]无效

1 个答案:

答案 0 :(得分:1)

初始化实例字段时,不能引用其他实例字段。您需要在构造函数中初始化它。

您正在完全正确地声明对象的类型;那里没有任何改变。