Multiple domain web hosting - Chapter 6 Methods 199 23 24 // x

Chapter 6 Methods 199 23 24 // x passed by reference and method modifies 25 // original variable’s value 26 void SquareRef( ref int x ) 27 { 28 x = x * x; 29 } 30 31 // x passed as out parameter and method initializes 32 // and modifies original variable’s value 33 void SquareOut( out int x ) 34 { 35 x = 6; 36 x = x * x; 37 } 38 39 // x passed by value and method cannot modify 40 // original variable’s value 41 void Square( int x ) 42 { 43 x = x * x; 44 } 45 46 private void showOutputButton_Click( object sender, 47 System.EventArgs e ) 48 { 49 int y = 5; // create new int and initialize to 5 50 int z; // declare z, but do not initialize it 51 52 // display original values of y and z 53 outputLabel.Text = “Original value of y: ” + y + “n”; 54 outputLabel.Text += 55 “Original value of z: uninitializednn”; 56 57 // pass y and z by reference 58 SquareRef( ref y ); 59 SquareOut( out z ); 60 61 // display values of y and z after modified by methods 62 // SquareRef and SquareOut 63 outputLabel.Text += 64 “Value of y after SquareRef: ” + y + “n”; 65 outputLabel.Text += 66 “Value of z after SqaureOut: ” + z + “nn”; 67 68 // pass y and z by value 69 Square( y ); 70 Square( z ); 71 72 // display unchanged values of y and z 73 outputLabel.Text += “Value of y after Square: ” + y + “n”; 74 outputLabel.Text += “Value of z after Square: ” + z + “n”; 75 Fig. 6.8 Demonstrating ref and out parameters. (Part 2 of 3.)
If you are in need for chaep and reliable webhost to host your website, our recommendation is http web server services.

Leave a Reply