C#不定长参数的使用

在使用不定长参数params时,如果除了params参数还有其他参数,params参数要作为最后一个参数.否则程序无法识别.

    public void test(int sd, params int[] arr)//不定长参数前要加params
{
Console.WriteLine("第一个参数是:{0};第二个参数是:{1};第三个参数是:{2};", sd, arr[0], arr[1]);
}
static void Main(string[] args)
{
Program ps = new Program();
ps.test(22, 5, 6, 7, 8, 9, 10);

Console.Read();
}



原文地址:https://www.cnblogs.com/fumj/p/2412441.html