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...
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
Must Read
What Is It?
This exception means that you're trying to access a collection item by index, using an invalid index. An index is invalid when it's lower than the collection's lower bound or greater than or equal to the number of elements it contains.