Free web hosting services - 266 Arrays Chapter 7 Column 0 Column 1
266 Arrays Chapter 7 Column 0 Column 1 Column 2 Column 3 Row 0 Row 1 Row 2 a[0, 0] a[0, 1] a[0, 2] a[0, 3] a[1, 0] a[1, 1] a[1, 2] a[1, 3] a[2, 0] a[2, 1] a[2, 2] a[2, 3] Column index (or subscript) Row index (or subscript) Array name Fig. 7.13 Double-subscripted array with three rows and four columns. Every element in array a is identified in Fig. 7.13 by an element name of the form a[i,j], in which a is the name of the array, and i and j are the subscripts that uniquely identify the row and column of each element in a. Notice that the names of the elements in the first row all have a first subscript of 0; the names of the elements in the fourth column all have a second subscript of 3. Multiple-subscripted arrays can be initialized in declarations like single-subscripted arrays. A double-subscripted array b with two rows and two columns could be declared and initialized with int[,] b = new int[ 2, 2 ]; b[ 0, 0 ] =1; b[ 0, 1 ] =2; b[ 1, 0 ] =3; b[ 1, 1 ] =4; or this can be written on one line using an initializer list as shown below: int[,] b = { { 1, 2 }, { 3, 4 } }; The values are grouped by row in braces. Thus, 1 and 2 initialize b[0,0] and b[0,1], and 3 and 4 initialize b[1,0] and b[1,1]. The compiler determines the number of rows by counting the number of sub-initializer lists (represented by sets of braces) in the main initializer list. The compiler determines the number of columns in each row by counting the number of initializer values in the sub-initializer list for that row. Method GetLength returns the length of a particular array dimension. In the preceding example, b.GetLength(0)returns the length of the zeroth dimension of b, which is 2. Jagged arrays are maintained as arrays of arrays. Unlike in rectangular arrays, the arrays that compose jagged arrays can be of different lengths. The declaration int[][] c = new int[ 2 ][]; // allocate rows // allocate and initialize elements in row 0 c[ 0 ] = new int[] { 1,2 };
If you are looking for cheap and quality webhost to host and run your website check Jboss Web Hosting services.