13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 19 Arrays19. ArraysAn array is a data structure that contains a number of variables which are accessed through computedindices. 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.An array has a rank which determines the number of indices associated with each array element. The rank ofan array is also referred to as the dimensions of the array. An array with a rank of one is called a singledimensionalarray. An array with a rank greater than one is called a multi-dimensional array. Specific sizedmulti-dimensional arrays are often referred to as two-dimensional arrays, three-dimensional arrays, and soon. Each dimension of an array has an associated length which is an integral number greater than or equal tozero. The dimension lengths are not part of the type of the array, but rather are established when an instanceof the array type is created at run-time. The length of a dimension determines the valid range of indices forthat dimension: For a dimension of length N, indices can range from 0 to N – 1 inclusive. The total numberof elements in an array is the product of the lengths of each dimension in the array. If one or more of thedimensions 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, including an array type.19.1 Array typesAn array type is written as a non-array-type followed by one or more rank-specifiers:array-type:non-array-type rank-specifiersnon-array-type:typerank-specifiers:rank-specifierrank-specifiers rank-specifierrank-specifier:[ dim-separators opt ]dim-separators:,dim-separators ,A non-array-type is any type that is not itself an array-type.The rank of an array type is given by the leftmost rank-specifier in the array-type: A rank-specifier indicatesthat the array is an array with a rank of one plus the number of “,” tokens in the rank-specifier.The element type of an array type is the type that results from deleting the leftmost rank-specifier:• An array type of the form T[R] is an array with rank R and a non-array element type T.• An array type of the form T[R][R 1 ]…[R N ] is an array with rank R and an element type T[R 1 ]…[R N ].In effect, the rank-specifiers are read from left to right before the final non-array element type. [Example:The type int[][,,][,] is a single-dimensional array of three-dimensional arrays of two-dimensionalarrays of int. end example]At run-time, a value of an array type can be null or a reference to an instance of that array type.275

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!