272 Arrays Chapter 7 Fig. 7.15 Example using

272 Arrays Chapter 7 Fig. 7.15 Example using double-subscripted arrays. (Part 3 of 3.) of the third row are compared with variable lowGrade. When execution of the nested structure is complete, lowGrade contains the smallest grade in the double-subscripted array. Method Maximum works similarly to method Minimum. Method Average takes one argument a single-subscripted array of test results for a particular student. When Averageis called (line 59), the argument grades[i] specifies that a particular row of the double-subscripted array grades is to be passed to Average. For example, the argument grades[1]represents the four values (a single- subscripted array of grades) stored in the second row of the double-subscripted array grades. Remember that a jagged two-dimensional array is an array with elements that are single-subscripted arrays. Method Average calculates the sum of the array elements, divides the total by the number of test results and then returns the floating-point result cast as a double value (line 101). 7.10 foreach Repetition Structure C# provides the foreach retition structure for iterating through values in data structures, such as arrays. When used with one-dimensional arrays, foreach behaves like a for structure that iterates through the range of indices from 0 to the array s Length. Instead of a counter, foreach uses a variable to represent the value of each element. The program in Fig. 7.16 uses the foreach structure to determine the minimum value in a two-dimensional array of grades. 1 // Fig. 7.16: ForEach.cs 2 // Demonstrating for/each structure. 3 using System; 4 5 class ForEach 6 { 7 // main entry point for the application 8 static void Main( string[] args ) 9 { Fig. 7.16 Using ForEach/Next with an array. (Part 1 of 2.)
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.

Leave a Reply