Array out of bound exception
please tell be c# program which handle Arrayoutofbound exception
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Sunny SharmaRank #223 · 11.1K pointsPosted Oct 3, 2013, 8:55 PM EDT
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 :)