Only one paras keyword is allowed in the method declaration, and the keyword can only be the last one.
Copy Code code as follows:
Using System;
/******************************
* chapter:c# difficulties one by one break (three)
* Author: Wang Hongjian
* date:2010-1-16
* blog:http://www.51obj.cn/
* email:walkingp@126.com
* Description: Use of array parameter params
* ***************************/
Namespace Testparams
{
Class Program
{
public static Class Paramsclass
{
<summary>
Two parameters, last argument is an array parameter
</summary>
<param name= "num" ></param>
<param name= "args" ></param>
public static void Paramsmethod (int num,params string[] args)
{
foreach (String _args in args)
{
Console.WriteLine (_args);
}
Console.WriteLine ("Total Num" + num);
Console.readkey ();
}
}
static void Main (string[] args)
{
String[] Strarr ={"Wang Hongjian", "Chenchen", "Dodo"};
int personnum = Strarr.length;
Paramsclass.paramsmethod (Personnum, Strarr);
}
}
}
Operation Effect:
Summarizing ref, out, and params,ref is the result of the parameter influence within the reference method, out is the result of the parameter return to the main method in the reference method, and the params is passing the variable homogeneous parameter (that is, the array) into the parameter. Use the medium ref for the data that needs to be invoked within the reference method. Out is used to manipulate the main method using a reference method, and prarams is used for situations where the parameter length is unknown.
SOURCE download