Chapter 7 Arrays 251 // (Web site development) Fig. 7.8: PassArray.cs
Chapter 7 Arrays 251 // Fig. 7.8: PassArray.cs // Passing arrays and individual elements to methods. using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; public class PassArray : System.Windows.Forms.Form { private System.Windows.Forms.Button showOutputButton; private System.Windows.Forms.Label outputLabel; // Visual Studio .NET generated code [STAThread] static void Main() { Application.Run( new PassArray() ); } private void showOutputButton_Click( object sender, System.EventArgs e ) { int[] a = { 1, 2, 3, 4, 5 }; outputLabel.Text = “Effects of passing entire array ” + “call-by-reference:nnThe values of the original ” + “array are:nt”; for ( int i = 0; i < a.Length; i++ ) outputLabel.Text += " " + a[ i ]; ModifyArray( a ); // array is passed by reference outputLabel.Text += "nnThe values of the modified array are:nt"; // display elements of array a for ( int i = 0; i < a.Length; i++ ) outputLabel.Text += " " + a[ i ]; outputLabel.Text += "nnEffects of passing array " + "element call-by-value:nna[ 3 ] before " + "ModifyElement: " + a[ 3 ]; // array element passed call-by-value ModifyElement( a[ 3 ] ); outputLabel.Text += "na[ 3 ] after ModifyElement: " + a[ 3 ]; } Fig. 7.8 Passing arrays and individual array elements to methods. (Part 1 of 2.)
Check Tomcat Web Hosting services for best quality webspace to host your web application.