EDN Admin
Well-known member
Hi Mr Programers
Im reading C# program form a E-book and I have problem in understanding this book. Actually Im doing as there is written, but have many error appearing in my VS... there is not shown how did they design all this In IDE, but only code have been show and
I could get result as they have shown end of this example in the book. Code was as following
I am write code in VS 2010
1 // Fig. 7.8: PassArray.
2 // Passing arrays and individual elements to methods.<br/>
3 using System;<br/>
4 using System.Drawing;<br/>
5 using System.Collections;<br/>
6 using System.ComponentModel;<br/>
7 using System.Windows.Forms;<br/>
8 using System.Data;<br/>
9<br/>
10 public class PassArray : System.Windows.Forms.Form<br/>
11 {<br/>
12 private System.Windows.Forms.Button showOutputButton;<br/>
13 private System.Windows.Forms.Label outputLabel;<br/>
14<br/>
15 // Visual Studio .NET generated code<br/>
16<br/>
17 [STAThread]<br/>
18 static void Main()<br/>
19 {<br/>
20 Application.Run( new PassArray() );<br/>
21 }<br/>
22<br/>
23 private void showOutputButton_Click( object sender,<br/>
24 System.EventArgs e )<br/>
25 {<br/>
26 int[] a = { 1, 2, 3, 4, 5 };<br/>
27<br/>
28 outputLabel.Text = "Effects of passing entire array " +<br/>
29 "call-by-reference:nnThe values of the original " +<br/>
30 "array are:nt";<br/>
31<br/>
32 for ( int i = 0; i < a.Length; i++ )<br/>
33 outputLabel.Text += " " + a[ i ];<br/>
34<br/>
35 ModifyArray( a ); // array is passed by reference<br/>
36<br/>
37 outputLabel.Text +=<br/>
38 "nnThe values of the modified array are:nt";<br/>
39<br/>
40 // display elements of array a<br/>
41 for ( int i = 0; i < a.Length; i++ )<br/>
42 outputLabel.Text += " " + a[ i ];<br/>
43<br/>
44 outputLabel.Text += "nnEffects of passing array " +<br/>
45 "element call-by-value:nna[ 3 ] before " +<br/>
46 "ModifyElement: " + a[ 3 ];<br/>
47<br/>
48 // array element passed call-by-value<br/>
49 ModifyElement( a[ 3 ] );<br/>
50<br/>
51 outputLabel.Text +=<br/>
52 "na[ 3 ] after ModifyElement: " + a[ 3 ];<br/>
53 }<br/>
54<br/>
55 // method modifies the array it receives,<br/>
56 // original will be modified<br/>
57 public void ModifyArray( int[] b )<br/>
58 {<br/>
59 for ( int j = 0; j < b.Length; j++ )<br/>
60 b[ j ] *= 2;<br/>
61 }<br/>
62<br/>
63 // method modifies the integer passed to it<br/>
64 // original will not be modified<br/>
65 public void ModifyElement( int e )<br/>
66 {<br/>
67 outputLabel.Text +=<br/>
68 "nvalue received in ModifyElement: " + e;<br/>
69<br/>
70 e *= 2;<br/>
71<br/>
72 outputLabel.Text +=<br/>
73 "nvalue calculated in ModifyElement: " + e;<br/>
74 }<br/>
75 }
Please tell what is not written here...and what should I do in IDE first
View the full article
Im reading C# program form a E-book and I have problem in understanding this book. Actually Im doing as there is written, but have many error appearing in my VS... there is not shown how did they design all this In IDE, but only code have been show and
I could get result as they have shown end of this example in the book. Code was as following
I am write code in VS 2010
1 // Fig. 7.8: PassArray.
2 // Passing arrays and individual elements to methods.<br/>
3 using System;<br/>
4 using System.Drawing;<br/>
5 using System.Collections;<br/>
6 using System.ComponentModel;<br/>
7 using System.Windows.Forms;<br/>
8 using System.Data;<br/>
9<br/>
10 public class PassArray : System.Windows.Forms.Form<br/>
11 {<br/>
12 private System.Windows.Forms.Button showOutputButton;<br/>
13 private System.Windows.Forms.Label outputLabel;<br/>
14<br/>
15 // Visual Studio .NET generated code<br/>
16<br/>
17 [STAThread]<br/>
18 static void Main()<br/>
19 {<br/>
20 Application.Run( new PassArray() );<br/>
21 }<br/>
22<br/>
23 private void showOutputButton_Click( object sender,<br/>
24 System.EventArgs e )<br/>
25 {<br/>
26 int[] a = { 1, 2, 3, 4, 5 };<br/>
27<br/>
28 outputLabel.Text = "Effects of passing entire array " +<br/>
29 "call-by-reference:nnThe values of the original " +<br/>
30 "array are:nt";<br/>
31<br/>
32 for ( int i = 0; i < a.Length; i++ )<br/>
33 outputLabel.Text += " " + a[ i ];<br/>
34<br/>
35 ModifyArray( a ); // array is passed by reference<br/>
36<br/>
37 outputLabel.Text +=<br/>
38 "nnThe values of the modified array are:nt";<br/>
39<br/>
40 // display elements of array a<br/>
41 for ( int i = 0; i < a.Length; i++ )<br/>
42 outputLabel.Text += " " + a[ i ];<br/>
43<br/>
44 outputLabel.Text += "nnEffects of passing array " +<br/>
45 "element call-by-value:nna[ 3 ] before " +<br/>
46 "ModifyElement: " + a[ 3 ];<br/>
47<br/>
48 // array element passed call-by-value<br/>
49 ModifyElement( a[ 3 ] );<br/>
50<br/>
51 outputLabel.Text +=<br/>
52 "na[ 3 ] after ModifyElement: " + a[ 3 ];<br/>
53 }<br/>
54<br/>
55 // method modifies the array it receives,<br/>
56 // original will be modified<br/>
57 public void ModifyArray( int[] b )<br/>
58 {<br/>
59 for ( int j = 0; j < b.Length; j++ )<br/>
60 b[ j ] *= 2;<br/>
61 }<br/>
62<br/>
63 // method modifies the integer passed to it<br/>
64 // original will not be modified<br/>
65 public void ModifyElement( int e )<br/>
66 {<br/>
67 outputLabel.Text +=<br/>
68 "nvalue received in ModifyElement: " + e;<br/>
69<br/>
70 e *= 2;<br/>
71<br/>
72 outputLabel.Text +=<br/>
73 "nvalue calculated in ModifyElement: " + e;<br/>
74 }<br/>
75 }
Please tell what is not written here...and what should I do in IDE first
View the full article