将变量分配给锯齿状数组的特定尺寸

问题描述 投票:0回答:1

我正在通过制作一个俄罗斯方块游戏来学习C#,下面是一个3d数组,它代表一个Tetromino及其四个旋转,我想为其中的2d数组之一分配一个变量。我习惯使用JavaScript,无法弄清语法。

           int[][][] T = new int[][][]
            {
               new int[][] {
                    new int[]{0,1,0},
                    new int[]{1,1,1},
                    new int[]{0,0,0}
                },
                new int[][]{
                    new int[]{0,1,0},
                    new int[]{0,1,1},
                    new int[]{0,1,0}
                },
                new int[][]{
                    new int[]{0,0,0},
                    new int[]{1,1,1},
                    new int[]{0,1,0},
                },
                new int[][]{
                    new int[]{0,1,0},
                    new int[]{1,1,0},
                    new int[]{0,1,0}
                }
            };

            int position = 0; 
            //this is what i would like to do but it throws a error
            int[][] activePiece = T[position];

            //example in javascript
            //const activePiece = T[position]
            //and activePiece would equal
            //[[0,1,0]
            //[1,1,1]
            //[0,0,0]]

c# arrays jagged-arrays
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.