About these three keywords before you can study the original operation
usingSystem;usingSystem.Collections.Generic;usingSystem.Text;namespaceparamsrefout{classProgram {Static voidChangeValue (inti) {i=5; Console.WriteLine ("The ChangeValue method changed the value"+i.tostring ()); } Static voidMain (string[] args) { inti =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.
usingSystem;usingSystem.Collections.Generic;usingSystem.Text;namespaceparamsrefout{classNumber { Public Static voidUseparams (params int[] list) { for(intI=0; i<list. length;i++) {Console.WriteLine (list[i]); } } Static voidMain (string[] args) {Useparams (1,2,3); int[] MyArray =New int[3] {Ten, One, A}; 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
usingSystem;usingSystem.Collections.Generic;usingSystem.Text;namespaceparamsrefout{classNumber {Static voidMain () {intval =0; Method (refval); Console.WriteLine (Val. ToString ()); } Static voidMethod (ref inti) {i= -; } }}
3) out keyword: Out is similar to ref but out does not need to be initialized.
Three keywords in C # params,ref,out