Information Technology Reference
In-Depth Information
Arrays
An array is a set of uniform data elements, represented by a single variable name. The individ-
ual elements are accessed using the variable name and one or more indexes between square
brackets, as shown here:
Array name Index
MyArray[4]
Definitions
Let's start with some important definitions having to do with arrays in C#.
Elements : The individual data items of an array are called elements . All elements of an array
must be of the same type.
Rank/dimensions : Arrays can have any positive number of dimensions . The number of
dimensions an array has is called its rank .
Dimension length : Each dimension of an array has a length , which is the number of posi-
tions in that direction.
Array length : The total number of elements contained in an array, in all dimensions, is
called the length of the array.
Important Details
Besides the preceding definitions, there are several high-level facts about C# arrays that I
should mention before launching into a discussion of arrays.
￿
Once an array is created, its size is fixed. C# does not support dynamic arrays.
Array indexes are 0-based . That is, if the length of a dimension is n , the index values range
from 0 to n - 1. For example, Figure 14-1 shows the dimensions and lengths of two exam-
ple arrays. Notice that for each dimension, the indexes range from 0 to length - 1.
￿
Figure 14-1. Dimensions and sizes
Search WWH ::




Custom Search