C#多维矩形数组?

时间:2015-12-07 20:07:44

标签: c# arrays multidimensional-array

我用这个矩形阵列撞墙了。我只是一个一维阵列,但有一个有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
        }
    }
}

它停止了工作,我无法想象我能做什么......有人可以帮忙吗?

1 个答案:

答案 0 :(得分:3)

根据我的理解,在行

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

对于第二行中的循环,您的意思是增加j,但是会增加i