For an array access, the primary-expression of the element-access must be a value of an array-type. The number of expressions in the expression-list must be the same as the rank of the array-type, and each expression must be of type int
or of a type that can be implicitly converted to int
.
The result of evaluating an array access is a variable of the element type of the array, namely the array element selected by the value(s) of the expression(s) in the expression-list.
The run-time processing of an array access of the form P[A]
, where P
is a primary-expression of an array-type and A
is an expression-list, consists of the following steps:
P
is evaluated. If this evaluation causes an exception, no further steps are executed.int
is performed. If evaluation of an index expression or the subsequent implicit conversion causes an exception, then no further index expressions are evaluated and no further steps are executed.P
is checked to be valid. If the value of P
is null
, a NullReferenceException
is thrown and no further steps are executed.P
. If one or more values are out of range, an IndexOutOfRangeException
is thrown and no further steps are executed.