Чтобы легко понять проблему, предположим, что мы написали этот код:
static void Main(string[] args)
{
string[] test = new string[3];
test[0]= "hello1";
test[1]= "hello2";
test[2]= "hello3";
for (int i = 0; i <= 3; i++)
{
Console.WriteLine(test[i].ToString());
}
}
Результат будет:
hello1
hello2
hello3
Unhandled Exception: System.IndexOutOfRangeException: Index was outside the bounds of the array.
Размер массива равен 3 (индексы 0, 1 и 2), но при попытке получить доступ за пределами границ с помощью (3) он выдает исключение.