An array is a reference type that contains variables accessed through computed indices. The variables contained in an array, also called the elements of the array, are all of the same type, and this type is called the element type of the array. The elements of an array come into existence when an array instance is created, and cease to exist when the array instance is destroyed. Each element of an array is initialized to the default value of its type. The type System.Array
is the abstract base type of all array types. Every array type inherits the members declared by the System.Array
type and is convertible to it (and Object
).
An array has a rank that determines the number of indices associated with each array element. The rank of an array is also referred to as the number of dimensions of the array. An array with a rank of one is called a single-dimensional array, and an array with a rank greater than one is called a multi-dimensional array.
Each dimension of an array has an associated length. The dimension lengths are not part of the type of the array, but rather are established when an instance of the array type is created at runtime. The length of a dimension determines the valid range of indices for that dimension: for a dimension of length N
, indices can range from 0
to N – 1
, inclusive. If a dimension is of length zero, then there are no valid indices for that dimension. The total number of elements in an array is the product of the lengths of each dimension in the array. If one or more of the dimensions of an array have a length of zero, the array is said to be empty. The element type of an array can be any type except an array type.
Array types are specified by adding a modifier to an existing type name. The modifier consists of a left parenthesis, a set of zero or more commas, and a close parenthesis. The type modified is the element type of the array, and the number of dimensions is the number of commas, plus one. A variable may also be declared to be of an array type by putting an array type modifier or an array initialization modifier on the variable name. In that case, the array element type is the type given in the declaration, and the array dimensions are determined by the variable name modifier. Since an array may not have an array type as its element type, it is not legal to have an array type modifier on both a variable name and a type name in the same declaration.
(
[ RankList ] )
,
|,