Only one paras keyword is allowed in the method declaration, and this keyword can only be the last one.
CopyCode The Code is as follows: using system;
/******************************
* Chapter: C # difficulties one by one (3)
* Author: Wang Hongjian
* Date: 2010-1-16
* blog: http://www.51obj.cn/
* Email: walkingp@126.com
* description: use of array parameter Params
****************************/
namespace testparams
{< br> class Program
{< br> Public static class paramsclass
{< br> ///
// /Two parameters, the last parameter is the array parameter
///
///
///
Public static void paramsmethod (INT num, params string [] ARGs)
{< br> foreach (string _ ARGs in ARGs)
{< br> console. writeline (_ ARGs);
}< br> console. writeline ("total num is" + num);
console. readkey ();
}< BR >}< br> static void main (string [] ARGs)
{< br> string [] strarr = {"Wang Hongjian", "Chenchen", "dodo" };< br> int personnum = strarr. length;
paramsclass. paramsmethod (personnum, strarr);
}< BR >}
Running effect:
To sum up ref, out, And Params, ref is the result of the parameter impact in the reference method; out is the result returned by the parameter in the reference method to the main method; and Params is the variable similar parameter (that is, the array) input parameters. In use, ref is used to call the data in the reference method. The out clause is used to operate the main method using the reference method, while the prarams clause is used for the case where the parameter length is unknown.
Source code download