The params is used when the number of parameters is variable, that is, the number of parameters is unknown.
You need to know the following points when using the params:
1. If the function passes a parameter containing more than one, the parameter array using the params tag needs to be placed in the last
The diagram shows clearly that there is no need to explain and only use the sort of a.
2, the params modified must be an array, but also a one-dimensional array
3. Params cannot be combined with ref, out
See HUNTS.C predecessor's article for details http://www.cnblogs.com/hunts/archive/2007/01/13/619620.html
4. The argument corresponding to the params modified parameter array can be an array name of the same type ( Note: Only one array name, multiple array names are not allowed ), or any number of variables of the same type as the elements of the array
Demo Code
classProgram {Static voidMain (string[] args) { //The display parameters are variable inti = Sum (1, -, at, the); Console.WriteLine (i); intj = Sum (1,1,3,2,4,4, -,555,6); Console.WriteLine (j); //an argument can be an array name int[] Arrayi =New int[5] {1,2,3,4,5 }; intArraysum =Sum (Arrayi); Console.WriteLine (Arraysum); Console.read (); } Static intSum (params int[] s) {intsum =0; foreach(intIinchs) {sum+=i; } returnsum; } }
C # need to know-length variable parameter--params