Regardless the the language, you will occasionally encounter one error blog post that the index exceeds the bounds of the array, that is, index was external the border of the array(the provided index of range exceeds the actual index of the array). For example, there are only 5 aspects in an array, and the index (subscript) of range starts indigenous 0. If the range is defined as a, and also the value of a<5> is bring away in this way, one out-of-bounds error that the array will it is in reported due to the fact that the index of the last element is 4, and also the last element should it is in a<4>.

Of course, such low-level mistakes are rarely made in the actual development process. They are usually dynamic arrays created by regimen operation, and also index was exterior the limit of the selection due come some circumstances that room not taken into consideration for the moment being. Then ns will offer some instances of common indexes past the border of the array. In order come meet various needs, I will give examples of language such as javascript and also C#.

I. Javascript variety index out of bounds

Example 1: The indexof variety starts native 1, the code is together follows:

var arr = <1, 2, 3, 4, 5, 6>;


for(var ns = 1; ns var tmp = arr;//When ns = arr.length, the index of range is the end of bounds}


for(var i = 0; i var tmp = arr;}

Example 2: The length of selection is not judged, and the arbitrary value causes array index out of bounds

If you want to obtain all the div tag of webpage, without judging how plenty of divs there are in advance, simply use the subscript to get the value, the code is together follows:

var arr = document.getElementsByTagName("div");var temp = arr<1>;

If there is no div or just one in the webpage, arr<1> will cause range out of border error. The exactly code must be judged by adding:

if(arr.length > 1)var temp = arr<1>;


You are watching: Index was outside the bounds of the array meaning

See more: Cobalt Ss 1/4 Mile - Quick Test: 2008 Chevrolet Cobalt Ss

Table of contents was outside the bounds of the selection in C#

If you desire to gain all text papers in a folder, if you usage the size of variety to gain the critical element, one error which table of contents was external the border of the range will occur. The code is as follows:

/// /// C# acquire all text papers in a folder/// /// Folder path private void GetTxtFiles(string path){DirectoryInfo di = brand-new DirectoryInfo(path);FileInfo<> arrFi = di.GetFiles("*.txt");

//Errorstring temp = arrFi.Name;//Get the last aspect with the size of array, the index of selection will be the end of bounds