Chapter 7 Arrays 241 6 7 class InitArray
Chapter 7 Arrays 241 6 7 class InitArray 8 { 9 // main entry point for application 10 static void Main( string[] args ) 11 { 12 string output = “”; 13 14 int[] x; // declare reference to an array 15 x = new int[ 10 ]; // dynamically allocate array and set 16 // default values 17 18 // initializer list specifies number of elements 19 // and value of each element 20 int[] y = { 32, 27, 64, 18, 95, 14, 90, 70, 60, 37 }; 21 22 const int ARRAY_SIZE = 10; // named constant 23 int[] z; // reference to int array 24 25 // allocate array of ARRAY_SIZE (i.e., 10) elements 26 z = new int[ ARRAY_SIZE ]; 27 28 // set the values in the array 29 for ( int i = 0; i < z.Length; i++ ) 30 z[ i ] = 2 + 2 * i; 31 32 output += "SubscripttArray xtArray ytArray zn"; 33 34 // output values for each array 35 for ( int i = 0; i < ARRAY_SIZE; i++ ) 36 output += i + "t" + x[ i ] + "t" + y[ i ] + 37 "t" + z[ i ] + "n"; 38 39 MessageBox.Show( output, 40 "Initializing an array of int values", 41 MessageBoxButtons.OK, MessageBoxIcon.Information ); 42 43 } // end Main 44 45 } // end class InitArray Fig. 7.3 Initializing element arrays in three different ways. (Part 2 of 2.)
We recommend high quality webhost to host and run your jsp application: christian web host services.