#154 – Using an Invalid Array Index Causes an Exception to Be Thrown

If you try to reference an array element using an index that is outside the declared range of the array, an IndexOutOfRangeException exception will be thrown.

            int[] scores = { 88, 99, 79, 88};
            Console.WriteLine("5th element? - {0}", scores[4]);    // IndexOutOfRangeException
Advertisements