7
Answers

System out of range exception at the end of the loop

Ram Prasad

Ram Prasad

3y
806
1

System is giving me out of range exception when p = 255. My understading is that with "OR operator, later part of if statement shoudl come into affet. However, it is not. Please advise on how to fix it.

for (int p = 0; p < 256; p++) 
{    
    if (buffer[p] == buffer[p + 1] || buffer[p] == buffer[p - 1])
    {
        //Code
    }
}

 

Answers (7)