What is an IndexOutOfRangeException / ArgumentOutOfRangeException and how do I fix it?

I have some code and when it executes, it throws a IndexOutOfRangeException, saying,

Index was outside the bounds of the array.

What does this mean, and what can I do about it?

Depending on classes used it can also be ArgumentOutOfRangeException

An exception of type ‘System.ArgumentOutOfRangeException’ occurred in mscorlib.dll but was not handled in user code Additional information: Index was out of range. Must be non-negative and less than the size of the collection.

5 Answers
5

Leave a Comment