BCL mscorlib [00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 ] 1.0.5000.0 2.0.0.0 4.0.0.0 All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe. System.SystemException System.Runtime.InteropServices.ComVisible(true)

The following example demonstrates an error that causes a exception.

`using System; public class IndexRangeTest { public static void Main() { int[] array = {0,0,0}; try { for (int i = 0; i<4; i++) { Console.WriteLine("array[{0}] = {1}",i,array[i]); } } catch (IndexOutOfRangeException e) { Console.WriteLine("Error: {0}",e); } } }`

The output is

`array[0] = 0 array[1] = 0 array[2] = 0 Error: System.IndexOutOfRangeException: Index was outside the bounds of the array. at IndexRangeTest.Main()`

The following Microsoft intermediate language (MSIL) instructions throw :

ldelem.<type>

ldelema

stelem.<type>

uses the HRESULT COR_E_INDEXOUTOFRANGE, which has the value 0x80131508.

The most common causes of this exception are miscalculating a lookup index, or using the wrong start or end point when iterating. For other causes, see Troubleshooting Exceptions: System.IndexOutOfRangeException.

For a list of initial property values for an instance of , see the constructors.

The exception that is thrown when an attempt is made to access an element of an array with an index that is outside the bounds of the array. This class cannot be inherited.

- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  This constructor initializes the property of the new instance to a system-supplied message that describes the error, such as "An array index is out of range." This message takes into account the current system culture.

  The following table shows the initial property values for an instance of .

  Property

  Value

  A null reference (Nothing in Visual Basic).

  The localized error message string.

  Initializes a new instance of the class.

  0
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  This constructor initializes the property of the new exception using the parameter. The content of is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture.

  The following table shows the initial property values for an instance of .

  Property

  Value

  A null reference (Nothing in Visual Basic).

  The error message string.

  Initializes a new instance of the class with a specified error message.

  The message that describes the error.
  0
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  An exception that is thrown as a direct result of a previous exception should include a reference to the previous exception in the property. The InnerException property returns the same value that is passed into the constructor, or a null reference (Nothing in Visual Basic) if the InnerException property does not supply the inner exception value to the constructor.

  The following table shows the initial property values for an instance of .

  Property

  Value

  The inner exception reference.

  The error message string.

  Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception.

  The error message that explains the reason for the exception.
  The exception that is the cause of the current exception. If the parameter is not a null reference (Nothing in Visual Basic), the current exception is raised in a catch block that handles the inner exception.
  0
0