索引超出了数组Rectangle C#的范围

时间:2015-02-05 08:00:59

标签: c# winforms

我正在尝试制作2个for循环,可以在数组中为我存储矩形但是当我运行for循环时,我得到错误消息:"索引超出了数组的范围" 有人可以解释一下我做错了吗?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;

namespace WindowsFormsApplication1
{
    class Game : GameEngine
{
    Rectangle[] Rect = new Rectangle[45];
    int blockX, blockY, blockW = 187, blockH=15, blockCount;
    public override void Render(Graphics g)
    {
        fpsCounter.Frame();
        i++;
        g.Clear(Color.Black);
        g.FillRectangle(Brushes.White, i / 2f, 20, 20, 20);
        g.FillRectangle(Brushes.Yellow, Cursor.Position.X, this.Height-(this.Height / 10), 200, 20);
        g.DrawString(fpsCounter.getFps().ToString(), Font, Brushes.Green, 5, 5);
        for (int j = 0; j < 3; j++)
        {
            for (int k = 0; i < 10; k++)
            {
                blockCount++;
                Rect[blockCount] = new Rectangle(blockX, blockY, blockW, blockH);
                blockX = blockX + blockW + 5;
            }
        blockY = blockY + blockH + 5;
        }
    }

    private FpsCounter fpsCounter = new FpsCounter();
    int i = 0;
    }
}

0 个答案:

没有答案