简体   繁体   English

C#多维矩形数组?

[英]C# Multidimensional Array Of Rectangles?

I've hit a wall with this array of rectangles. 我用这个矩形阵列打了一堵墙。 I was fine with simply a one dimensional array but with one with 4 columns I've just started banging my head on my wall... 我只是一个一维阵列,但是有一个有4列我只是开始敲我的头...

I've defined the array as: 我已将数组定义为:

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

Then these are used in conjunction to that: 然后这些结合使用:

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 };

And then trying to draw the rectangles through the multi array loop: 然后尝试通过多数组循环绘制矩形:

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
        }
    }
}

It's stopped working and I can't think what I can do.... Can anyone help? 它停止了工作,我无法想象我能做什么......有人可以帮忙吗?

To my understanding, in the lines 根据我的理解,在行中

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

for the loops in the second line you mean to increase j , but you increase i instead. 对于第二行中的循环,你的意思是增加j ,但是你增加了i

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM