配列に無い添字を指定すると出ます。
出るコード
int[] a = { 1, 2, 3 };
Console.WriteLine(a[3]); // 添字は 0〜2
エラーメッセージ
System.IndexOutOfRangeException: Index was outside the bounds of the array.
直し方
添字は 0 から。a.Length で長さを確認し、範囲内でアクセスします。
C#のエラー · エラー5
配列に無い添字を指定すると出ます。
int[] a = { 1, 2, 3 };
Console.WriteLine(a[3]); // 添字は 0〜2
System.IndexOutOfRangeException: Index was outside the bounds of the array.
添字は 0 から。a.Length で長さを確認し、範囲内でアクセスします。