This article mainly discusses the params keyword, the ref keyword, the Out keyword. Very good, with reference value, need to refer to a friend
About these three keywords before you can study the original operation
Using system;using system.collections.generic;using system.text;namespace paramsrefout{ class program { static void ChangeValue (int i) { i=5; Console.WriteLine ("The ChangeValue method changed the value" +i.tostring ()); } static void Main (string[] args) { int i = ten; Console.WriteLine ("The value of I is" +i.tostring ()); ChangeValue (i); Console.WriteLine ("The value of I is" + i.tostring ()); Console.ReadLine ();}}}
Observation of running results found
The value is not changed, that is, the operation at this point may be the same as the previous C language function operation
This article mainly discusses the params keyword, the ref keyword, the Out keyword.
1) The params keyword, which is given by the official explanation, is used in cases where the length of the method parameter is variable. Sometimes it is not possible to determine how many method parameters are in a method, and you can use the params keyword to solve the problem.
Using system;using system.collections.generic;using system.text;namespace paramsrefout{ class number { public static void Useparams (params int. [] list) {for (int i=0;i<list. length;i++) { Console.WriteLine (list[i]); } } static void Main (string[] args) { useparams (n/a); int[] MyArray = new Int[3] {10,11,12}; Useparams (MyArray); Console.ReadLine ();}}}
2) ref Keyword: Any changes you make to a parameter in a method will be reflected in the variable using the reference type parameter
Using system;using system.collections.generic;using system.text;namespace paramsrefout{ class number { static void Main () { int val = 0; Method (ref val); Console.WriteLine (Val. ToString ()); } static void Method (ref int i) { i =;} } }
3) out keyword: Out is similar to ref but out does not need to be initialized.