我有这个错误怎么解决? “grahamscandatamovement.exe”中出现了类型'system.indexoutofrangeexception'的未处理异常。
问题描述:
我使用我的程序时遇到这个问题
在此代码中:
i have this problem when i use my program
In this Code :
private void findSmallestPolygon()
{
int clockwise = 1;
int countclockwise = -1;
int l = 0,m = 1,i = 2;
finalPointArray = new int[count];
//take two point
finalPointArray[l] = 1;
finalPointArray[m] = 1;
Pen redPen;
SolidBrush blueBrush = new SolidBrush(Color.White);
redPen = new Pen(Color.Red,2);
//draw line
dc.DrawLine(redPen, new Point(xcordinate[0], ycordinate[0]), new Point(xcordinate[1], ycordinate[1]));
这是一个问题:
Here IS A Problem With :
finalPointArray[m] = 1;
请点击!
什么我试过了:
i试图解决它,但我不能!
请帮助我
Olease HElp !
What I have tried:
i tried to fix it but i cant !
Please Help ME
答
初始化finalPointArray
持有count
项目数量。您没有显示计数
是什么,但可能太小而无法容纳由变量m
定义的项目。 />
最好使用调试器并查看变量的实际值以便更好地解释。还要记住,索引从0开始,所以如果你有3个项目,索引将是0,1和2.
作为旁注,我建议定义方法内的变量。如果需要从方法外部获取信息,则将其作为参数传递通常是一种好习惯。这使程序更容易调试,修改和理解
You initialize thefinalPointArray
to holdcount
amount of items. You don't show what thecount
is but probably too small to hold an item defined by variablem
.
Best to use the debugger and see the actual values of the variables to better interpret. Also remember that indexing starts from 0 so if you have 3 items the indexes will be 0,1, and 2.
As a side comment, I would advise to define the variables inside the method. If information is needed from outside the method, it's often a good practice to pass it as a parameter. This makes the program easier to debug, modify, and understand