
1 class Program 2 { 3 //数组是引用类型 4 //假如把数组或类等别的引用类型传送给方式,相匹配的方式便会应用该引用类型改写数组中值, 5 //而新值会反射面到初始数组上 6 static void SomeFunction(int[] ints, int i) 7 { 8 ints[0]= 100; 9 i = 10; 10 } 11 12 //ref主要参数;应用关键词的主要参数会,方式会危害到相匹配主要参数的标值更改 13 //并且ref主要参数必须复位 14 static void SomeFunction1(ref int j) 15 { 16 j = 100; 17 } 18 19 //out主要参数;out主要参数能够不用复位 20 //该主要参数根据引入传送,方式回到w是会保存对w标值的更改 21 static void SomeFunction2(out int w) 22 { 23 w = 100; 24 } 25 26 static void Main(string[] args) 27 { 28 #region SomeFunction 29 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 //輸出結果:100,1 40 //在其中i的之是沒有转变的 41 42 #endregion 43 44 #region SomeFunction1 45 46 int j = 1;//恰当 47 //int j;//不正确 48 49 SomeFunction1(ref j); 50 51 Console.WriteLine(j); 52 53 //輸出結果:100 54 //j的标值发生改变 55 56 #endregion 57 58 #region SomeFunction2 59 60 int w;//恰当 61 //int w = 1;//恰当 62 63 SomeFunction2(out w); 64 65 Console.WriteLine(w); 66 67 //輸出結果:100 68 //w的标值发生改变 69 70 #endregion 71 } 72 }