C#矩形的多维数组

本文关键字:数组 | 更新日期: 2023-09-27 18:25:58

我用这个矩形阵列碰到了一堵墙。我对简单的一维数组很满意,但对于一个有4列的数组,我刚刚开始把头撞在墙上。。。

我将数组定义为:

private Rectangle[,] brick = new Rectangle[2, 8];

然后这些与之结合使用:

int[,] brickLocation = { {0, 0}, {0,21}, {0,42}, {0, 63}, {0, 84}, {0, 105}, {0, 126},
                             {61, 0}, {61,21}, {61,42}, {61, 63}, {61, 84}, {61, 105}, {61, 126} };
bool[] brickLive = { true, true, true, true, true, true, true,
                       true, true, true, true, true, true, true };

然后尝试通过多阵列循环绘制矩形:

for (int i = 0; i < brickLive.Length; i++)
{
    for (int j = 0; j < brickLive.Length; i++)
    {
        if (brickLive[i] == true)
        {
            brick[i, j] = new Rectangle(brickLocation[i, 0], brickLocation[i, 1], brkLength, brkHeight);
                    brickPaper.DrawRectangle(brickPen, brick[i, j]);
        }
        else
        {
            continue; //move onto next brick
        }
    }
}

它停止工作了,我想不出我能做什么……有人能帮忙吗?

C#矩形的多维数组

据我所知,在行

for (int i = 0; i < brickLive.Length; i++)
for (int j = 0; j < brickLive.Length; i++)

对于第二行中的循环,您的意思是增加j,但实际上增加了i