Home > Net >  The for loop, if the array is normal, the else error
The for loop, if the array is normal, the else error

Time:03-20




Runtime, if is normal, else the index exceeded array bounds

CodePudding user response:

Obviously array Pib and enValue differ long, Pib shorter than enValue, when I larger existence enValue [I] without Pib [I].

CodePudding user response:

Log out all of the code, just leave a assignment code, circulation again to see if the ultra boundary,

CodePudding user response:

Has nothing to do with the if and the else

According to your description, you don't write any if the else will be wrong,

Because you assume that the length of the array must be 85, according to assert that the programming, the first thing you should assert that guaranteed data length must be 85

If (enValue. The Count () & lt; 85)
{
//is unusual, the array length is less than 85
}

Or written
for(i=0; i CodePudding user response:

Problem is an array, in crossing the line of the points, is precisely the else, has nothing to do with the else itself, if there is no else, to the point, as well as crossing the line,

CodePudding user response:

An error, you say that you should look at what's wrong? Array index than the border?

Know what is wrong, you probably wouldn't have asked if the else questions,

CodePudding user response:

The same as pib array length and the cycle

CodePudding user response:

Is certainly Pib array length is less than the length of enValue
Can it handle
Int loopTimes=enValue. Length> Pib. Length? Pib. Length: enValue. Length;
for(int i=0; i{
If (enValue [I]==1) {
Pib [I] BackColor=Color. Yellow;
}
The else {
Pib [I] BackColor=Color. Gray;
}
}

Or try... The catch to also go
for(int i=0; i<85; I++)
{
Try {
If (enValue [I]==1) {
Pib [I] BackColor=Color. Yellow;
}
The else {
Pib [I] BackColor=Color. Gray;
}
}
Catch {
//
}
}

CodePudding user response:

Thank you, problem solved
  •  Tags:  
  • C#
  • Related