且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

指数超出范围

更新时间:2022-04-15 21:28:49

嗯。

看看你在做什么:

Um.
Look at what you are doing:
int [] array = new int [100];

将数组声明为100个整数的单位维数组。

Declares array as a signle dimensional array of 100 integers.

array[200] = 3;

尝试访问具有100个元素的数组的元素201。 ..



但这不会编译:

Tries to access element 201 of an array with 100 elements...

But that won't compile:

array[a, b] = false;

数组不是二维数组,它是一维的。而且C#严格要求这样做 - 非常正确!



数组不是bool类型 - 它是整数。并且你不能将bool存储在整数位置!

array is not a two dimensional array, it's one dimensional. And C# is strict about such things - quite rightly!

And array isn't of type bool - it's integer. And you can't store a bool in an integer location!


它只是意味着

It simply means that
((oRange.Left + oRange.Width) - control.Left) > control.With






or

((oData.Top + oData.Height) - control.Top) > control.Height





现在由你决定为什么你的代码属于这种边缘情况。

***的选择是使用调试器和在执行时注意相关变量的值。





代码的第二部分还有4个大错字你提供了(你在所有循环中交换了变量名a / i和b / j)。

实际上它甚至不会编译,所以我想这只是你在写问题时犯的错误。

[/编辑]



Now it's up to you to find why your code falls into this edge-case.
Best option is to use the debugger and watch for the values of relevant variables while executing.


There are also 4 big typos in the second part of the code you provided (you swapped variable names a/i and b/j in all you for loops).
Actually it would not even compile, so I guess it's just a typo you made while writing your question.
[/Edit]