Zebra0.com

csharp arraysOut of bounds: An exception

Out of bounds: An exception

If we try to access an element beyond the last element there is a run time error.

If you change the for loop in the program to for(int j = 0; j < 6; j++) you will get a runtime exception.

There are 5 elements in the array, but they have indexes of 0 to 4, there in no element 5..


Please note that it is the programmer's responsibility to make sure that the subscript is never less than 0 or more than the size. Doing so will result in an "Index Out of Range exception".

That's all! Congratulations on completing all of the lessons in csharp!