Csharp/C Sharp by API/System/IndexOutOfRangeException

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

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);
    }
  }
}