Mega Code Archive

 
Categories / C# Book / 01 Language Basics
 

0051 Index out of range exception

When reference an index behind the length of an array C# generates and throws IndexOfOfRange exception. The following code generates the IndexOutOfRange exception. using System; class Program { static void Main(string[] args) { int[] intArray = new int[3]; Console.WriteLine(intArray[10]); } } The output: Unhandled Exception: System.IndexOutOfRangeException: Index was outside the bounds of the array. at Program.Main(String[] args)