ParamsYou can specify the parameter when the number of parameters is variable.
The benefit of a variable number parameter is that in some cases, it is convenient to provide the Implementation of an uncertain number of parameters. For example, calculate the weighting of any number and connect any string to a string.
Public void getsummator (string team, Params int [] numbers) {int result = 0; foreach (INT number in numbers) Result + = number; response. write (Team + "the calculated result is:" + result );}
The following code calls the Calculation Method on the page:
Getsummator ("Params keyword used", 1, 2, 3, 4, 3, 2, 56, 76); getsummator ("<br/> Params", 2,345,567,876, 34,213,444,655, 2222, 55565,232,121 );
Of course, you can write more ......
Run the command to see the effect.
Note:
The parameters modified by Params must be a one-dimensional array. In fact, multiple or any multiple parameters are usually controlled in the cluster mode. arrays are the simplest choice.
The parameter array modified by Params can be of any type. Therefore, to accept any type of parameters, you only need to set the array type to object.
Params must be the last in the parameter list and can only be used once.