Java에서 배열 IndexOutofBoundsException이 발생합니다. C#에서 이에 해당하는 것은 IndexOutOfRangeException입니다.
IndexOutOfRangeException은 Index가 배열 범위 밖에 있을 때 발생합니다.
예시
using System;
using System.IO;
using System.Collections.Generic;
namespace Demo {
class Program {
static void Main(string[] args) {
int[] arr = new int[3];
arr[0] = 5;
arr[1] = 7;
arr[2] = 8;
arr[4] = 24; // this shows an error
}
}
} 출력
다음은 출력입니다. 그것은 다음과 같은 오류를 보여줍니다 -
Unhandled Exception: System.IndexOutOfRangeException: Index was outside the bounds of the array.