268 Arrays Chapter 7 42 43 outputLabel.Text += (Ftp web hosting)
268 Arrays Chapter 7 42 43 outputLabel.Text += “n”; 44 } 45 46 outputLabel.Text += “nValues in array2 by row aren”; 47 48 // output values in array2 49 for ( int i = 0; i < array2.Length; i++ ) 50 { 51 for ( int j = 0; j < array2[ i ].Length; j++ ) 52 outputLabel.Text += array2[ i ][ j ] + " "; 53 54 outputLabel.Text += "n"; 55 } 56 57 } // end method showOutputButton_Click 58 } Fig. 7.14 Initializing multidimensional arrays. (Part 2 of 2.) The declaration of array1 (line 27) provides six initializers in two sublists. The first sublist initializes the first row of the array to the values 1, 2 and 3. The second sublist initializes the second row of the array to the values 4, 5 and 6. The declaration of array2 (line 30) creates a jagged array of 3 arrays (specified by the 3 in the first set of square brackets). Lines 31 33 initialize each subarray so that the first subarray contains the values 1 and 2, the second contains the value 3 and the last contains the values 4, 5 and 6. The for structure on lines 38 44 appends the elements of array1 to string output. Note the use of a nested for structure to output the rows of each double-subscripted array. In the nested for structures for array1, we use method GetLength to determine the number of elements in each dimension of the array. Line 38 determines the number of rows in the array by invoking array1.GetLength(0), and line 40 determines the number of columns in the array by invoking array1.GetLength( 1 ). Arrays with additional dimensions would require more deeply nested for loops to process. The nested for structures on lines 49 55 output the elements of jagged array array2. Recall that a jagged array is essentially an array that contains additional arrays as its elements. Line 49 uses the Length property of array2 to determine the number of rows in the jagged array. Line 51 determines the Length of each subarray with the expression array2[i].Length. Many common array manipulations use for repetition structures. For the remainder of this section, we will focus on manipulations of jagged arrays. Imagine a jagged array a,
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.