Skip to content

Array out of bound exception

pankaj durve

Asked Oct 3, 2013, 7:57 PM EDT1 answer
Share
LinkedInX
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.

  • Sunny  Sharma
    0
    Hi pankaj,

    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 :)
    0