【发布时间】:2014-04-11 01:34:45
【问题描述】:
当我运行它时,它说索引超出了数组的范围,但事实并非如此。 如果我改变 public static ConectorRec[] ch = new ConectorRec[74];到 ConectorRec[] ch = new ConectorRec[75];那么它们不会全部引用到一个对象,并且会在我的代码的其他部分引发其他错误。
using System;
using System.Drawing;
using System.Windows;
using System.Windows.Forms;
using System.Collections.Generic;
namespace Dots
{
public static class Conectors
{
public static ConectorRec[] ch = new ConectorRec[74];
public static void intitialize()
{
ch[0] = new ConectorRec(new Rectangle(10, 20, 10, 40));
ch[1] = new ConectorRec(new Rectangle(20, 10, 40, 10));
ch[2] = new ConectorRec(new Rectangle(20, 60, 40, 10));
ch[3] = new ConectorRec(new Rectangle(60, 20, 10, 40));
int t = 0;
int tt = 1;
for (int i = 4; i<73; i++)
{
t++;
if (t == 1)
{
ch[i] = new ConectorRec(new Rectangle(50 * tt + 20, 10, 40, 10));
}
if (t == 2)
{
ch[i] = new ConectorRec(new Rectangle(50 * tt + 20, 60, 40, 10));
}
if (t == 3)
{
tt++;
ch[i] = new ConectorRec(new Rectangle(50 * tt + 10, 20, 10, 40));
t = 0;
}
}
ch[74] = new ConectorRec(new Rectangle(10, 70, 10, 40));
}
}
}
请告诉我我做错了什么以及如何解决这个错误。
【问题讨论】:
-
please tell me what I am doing wrong- 你好像在用winforms。 -
我让它工作了我必须测试我的循环在哪里结束,然后必须像每个人所说的那样使索引更大
标签: c#