270 Arrays Chapter 7 // Fig. 7.15: DoubleArray.cs

270 Arrays Chapter 7 // Fig. 7.15: DoubleArray.cs // Manipulating a double-subscripted array. using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; public class DoubleArray : System.Windows.Forms.Form { private System.Windows.Forms.Button showOutputButton; private System.Windows.Forms.Label outputLabel; int[][] grades; int students, exams; // Visual Studio .NET generated code [STAThread] static void Main() { Application.Run( new DoubleArray() ); } private void showOutputButton_Click( object sender, System.EventArgs e ) { grades = new int[ 3 ][]; grades[ 0 ] = new int[]{ 77, 68, 86, 73 }; grades[ 1 ] = new int[]{ 96, 87, 89, 81 }; grades[ 2 ] = new int[]{ 70, 90, 86, 81 }; students = grades.Length; // number of students exams = grades[ 0 ].Length; // number of exams // line up column headings outputLabel.Text = ” “; // output the column headings for ( int i = 0; i < exams; i++ ) outputLabel.Text += "[" + i + "] "; // output the rows for ( int i = 0; i < students; i++ ) { outputLabel.Text += "ngrades[" + i + "] "; for ( int j = 0; j < exams; j++ ) outputLabel.Text += grades[ i ][ j ] + " "; } Fig. 7.15 Example using double-subscripted arrays. (Part 1 of 3.)
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

Leave a Reply