@@ -5,35 +5,37 @@ class Program
55 static void Main ( string [ ] args )
66 {
77 // Example for AddR
8- static void AddR ( ref int a , ref int b ) {
8+ static void AddR ( ref int a , ref int b )
9+ {
910 int tmp = a ;
1011 a = a + b ;
1112 b = tmp - b ;
1213 }
13-
14- int x = 4 , y = 3 ;
14+
15+ int x = 4 ,
16+ y = 3 ;
1517 Console . WriteLine ( $ "x is { x } , y is { y } .") ;
1618 AddR ( ref x , ref y ) ;
1719 Console . WriteLine ( $ "x is { x } , y is { y } .") ;
1820 // End of AddR example
19-
21+
2022 /*
2123 // This Test1 method would not compile
2224 static void Test1(int a, out int b){
2325 if (a > 0) { b = 12; }
2426 }
2527 // Uncomment Test1 to see for yourself.
2628 */
27-
29+
2830 /*
2931 // This Test2 method would not compile
3032 static void Test2(int a, out int b){
3133 if (b < 0) { b = a; }
3234 else { b = 10;}
3335 }
3436 // Uncomment Test2 to see for yourself.
35- */
36-
37+ */
38+
3739 // Example for NameChange
3840 static void NameChange (
3941 ref string nameP ,
@@ -45,8 +47,8 @@ out string oldnameP
4547 nameP = newnameP ;
4648 }
4749 // End of NameChange example
48-
49- string name = "Smith" ;
50+
51+ string name = "Smith" ;
5052 // This previous string is assumed given.
5153 string oldname ;
5254 Console . WriteLine ( "Enter new name." ) ;
@@ -55,25 +57,25 @@ out string oldnameP
5557 $ "New name: { name } \n Old name: { oldname } "
5658 ) ;
5759 // End of NameChange usage example
58-
60+
5961 // Example for AddLog
6062 string log ;
6163 int x1 = 4 ,
62- y1 = 3 ;
64+ y1 = 3 ;
6365 int result = AddLog ( x1 , y1 , out log ) ;
6466 Console . WriteLine ( log + "\n " + result ) ;
65-
67+
6668 // Solution for AddLog
6769 int AddLog ( int xP1 , int yP1 , out string logP )
6870 {
6971 logP = xP1 + " + " + yP1 + " = " + ( xP1 + yP1 ) + "." ;
7072 return xP1 + yP1 ;
7173 }
72-
74+
7375 // AddReset example
7476 int x2 = 2 ,
75- y2 = 3 ,
76- z2 ;
77+ y2 = 3 ,
78+ z2 ;
7779 AddReset ( ref x2 , ref y2 , out z2 ) ;
7880 Console . WriteLine ( $ "x2 = { x2 } , y2 = { y2 } , z2 = { z2 } .") ;
7981 // Solution for AddReset
@@ -85,5 +87,4 @@ void AddReset(ref int xP2, ref int yP2, out int zP2)
8587 }
8688 // Done with AddReset
8789 }
88-
8990}
0 commit comments