IndexOutOfRangeException.Message : IndexOutOfRangeException « System « C# / C Sharp by API






IndexOutOfRangeException.Message

 

using System;

public class Example10_2 {

  public static void Main() {

    try {
      int[] intArray = new int[5];
      for (int counter = 0; counter <= intArray.Length; counter++)
      {
        intArray[counter] = counter;
        Console.WriteLine("intArray[" + counter + "] = " + intArray[counter]);
      }
    }
    catch (IndexOutOfRangeException e)
    {
      Console.WriteLine("IndexOutOfRangeException occurred");
      Console.WriteLine("Message = " + e.Message);
      Console.WriteLine("Stack trace = " + e.StackTrace);
    }

  }

}

   
  








Related examples in the same category