System.IndexOutOfRangeException: Index was outside the bounds of the array

Hi,

anyone can explain this ?

thanks

It’s a .NET exception thrown when you try to access an index that doesn’t exist in the given array. For example, you have an array with three items, therefore indexes 0, 1 and 2, and you try to access index 3.

Hi Adbul,

As Martin mentioned, this is a .NET framework exception: This exception means that when 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. I just tried to put some C# example in a Visual studio environment for your understanding to see in what scenarios it throws the exception. Here is the screen shot:

In the below example I created an array of size 5. Arrays are 0 based; meaning the firs element has an index value ‘0’. So, we can access this array from 0 to 4. I was able to put 4 customers successfully, however, when trying to insert the 5 element, which is higher than the actual array size and it has thrown the error that you are trying to understand. Hope this helps. Good luck!