IndexOutOfRangeException in C# (part 1)
The
The following example throws the
In the above example, an
The
IndexOutOfRangeException
is an exception that will be thrown while accessing an element of a collection with an index that is outside of its range. It occurs when an invalid index is used to access a member of a collection.The following example throws the
IndexOutOfRange
exception:In the above example, an
arr
contains five elements. It will throw an IndexOutOfRange
exception when trying to access value more than its total elements. Above, trying to access the 6th element using arr[5]
will throw IndexOutOfRange
exception.