Object and type (array, ref, out), refout
1 class Program 2 {3 // The array is of reference type 4 // if other reference types such as arrays or classes are passed to the method, the corresponding method uses this reference type to adapt the values in the array. 5 // The new value is reflected to the original array. 6 static void SomeFunction (int [] ints, int I) 7 {8 ints [0] = 100; 9 I = 10; 10} 11 12 // ref parameter; if you use a keyword parameter, the method will change the value of the corresponding parameter 13 // and the ref parameter needs to initialize 14 static void SomeFunction1 (ref int j) 15 {16 j = 100; 17} 18 19 // out parameter; out parameter may not need to be initialized 20 // this parameter is passed through reference, if the return value is w, the value of w is retained. 21 static void SomeFunction2 (out int w) 22 {23 w = 100; 24} 25 26 static void Main (string [] args) 27 {28 # region SomeFunction29 30 int [] ints = {1, 2, 3, 4}; 31 int I = 1; 32 33 SomeFunction (ints, I ); 34 35 Console. writeLine (ints [0]); 36 Console. writeLine (I); 37 38 39 // output result: 100,140 // where I is 41 42 without change # endregion43 44 # region SomeFunction145 46 int j = 1; // correct 47 // int j; // error 48 49 SomeFunction1 (ref j); 50 51 Console. writeLine (j); 52 53 // output: 10054 // The value of j is changed 55 56 # endregion57 58 # region SomeFunction259 60 int w; // correct 61 // int w = 1; // correct 62 63 SomeFunction2 (out w); 64 65 Console. writeLine (w); 66 67 // output result: the value of 10068 // w is changed 69 70 # endregion71} 72}View Code