Array out of bound exception
please tell be c# program which handle Arrayoutofbound exception
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sunny SharmaPosted Oct 4, 2013, 12:55 AM
in C# you get IndexOutOfRangeException, instead of ArrayOutOfBound, when you try to access an index of an Array greater than it's upper bound. See the example below:
------------------------------------------------
int[] MyArray = new int[5];
MyArray[0] = 1;
MyArray[1] = 2;
MyArray[2] = 3;
MyArray[3] = 4;
MyArray[4] = 5;
------------------------------------------------
Here If you try to access MyArray[0] to MyArray[4] it will return the value (as index starts from 0), but as soon you try to access MyArray[5] or greater, you get an exception here of IndexOutOfRangeException.
Hope I answered your question, reply back for any clarification.
HTH :)