An array type is defined by specifying the element type of the array, the rank (number of dimensions) of the array, and the upper and lower bounds of each dimension of the array. All of these are included in any signature of an array type, although they may be marked as dynamically (rather than statically) supplied. Hence, no separate definition of the array type is needed.
Values of an array type are objects; hence an array type is a kind of object type (see Classes, Interfaces and Objects). Array objects are defined by the VOS to be a repetition of locations where values of the array element type are stored. The number of repeated values is determined by the rank and bounds of the array.
Note: In V1 only type signatures, not location signatures, are allowed as array element types.
Exact array types are created automatically by the VES when they are required. Hence, the operations on an array type are defined by the VOS. These generally are: indexing the array to read and write a value, computing the address of an element of the array (a managed pointer), and querying for the rank, bounds, and the total number of values stored in the array.
CLS Rule 14: Arrays elements must have a CLS-compliant type, a fixed number of dimensions, and all dimensions of the array must have zero lower bounds. While the abstract type System.Array is considered CLS-compliant it does have types that inherit from it but are not CLS-compliant.
CLS (consumer): there is no need to support arrays of other types, even when dealing with instances of System.Array.
CLS (extender): there is no need to provide syntax to define other types of arrays or to extend interfaces or classes that use other array types. Must provide access to the type System.Array, but may assume that all instances will have a CLS-compliant type.
CLS (framework): other array types may not appear in exposed members.
Array types form a hierarchy, with all array types inheriting from the type System.Array. This is an abstract class that represents all arrays regardless of the type of their elements or their rank. Arrays of one dimension with zero lower bound for their elements (sometimes called vectors) have a type based on the type of the elements in the array, regardless of the upper bound. Arrays with more than one dimension or one dimension but with non-zero lower bound have the same type if they have the same element type and rank, regardless of lower bound on the array. Zero-dimensional arrays are not supported.
Consider the following examples, using the syntax of the IL Assembler (ilasm):
Static specification of type | Actual type constructed | Allowed in CLS? |
---|---|---|
int32[] |
vector of int32 | Yes |
int32[0..5] |
vector of int32 | Yes |
int32[1..5] |
array, rank 1, of int32 | No |
int32[,] |
array, rank 2, of int32 | Yes |
int32[0..3, 0..5] |
array, rank 2, of int32 | Yes |
int32[1.., 0..] |
array, rank 2, of int32 | No |