初級 › Index was outside the bounds of the array の原因と直し方 › パターン4
Index was outside the bounds of the array の原因と直し方
配列やリストの範囲外アクセスで実行時に発生します。
1 class Program { 2 static void Main(string[] args) { 3 int[] vals = { 4, 8, 15 }; 4 System.Console.WriteLine(vals[__]); ^ 5 } 6 }
Unhandled exception. System.IndexOutOfRangeException: Index was outside the bounds of the array.
at Program.Main(String[] args) in Program.cs:line 4
空欄を埋めてビルドを通す
要素数3の配列に添字9はありません。範囲外アクセスはIndexOutOfRangeExceptionになります。
次の問題