首先说明下,以params关键字作为参数定义的方法,传入的都是动态参数,即参数大多为数组(一维),下面就来举例说明下不同的具体使用方法:
1:
public void Method5(params int[] arrint)
        {
            foreach (int i in arrint)
            {
                Console.WriteLine(i);
            }
        }
main方法中调用Method5:
MyClass mc = new MyClass();
int[] arrint = new int[] { 1, 2, 3 };
            mc.Method5(arrint);  
结果为:1 2 3
2:
public void Method5(params int[] arrint)
        {
            foreach (int i in arrint)
            {
                Console.WriteLine(i);
            }
        }
main方法中调用Method5:
MyClass mc = new MyClass();
mc.Method5(1,2,3,4,5);
结果为1 2 3 4 5
3:
public void Method5(string t, params int[] arrint)
        {
            Console.WriteLine(t);
            foreach (int i in arrint)
            {
                Console.WriteLine(i);
            }      
        }
Main方法中调用:
MyClass mc = new MyClass();
            mc.Method5("bb",1,2,3,4);  结果为:bb  1 2 3 4
或者:mc.Method5("bb");   结果为:bb
同时可以有
public void Method5(string a, int b)
        {
            Console.WriteLine("2222222");
        }
Main方法中调用:
MyClass mc = new MyClass();
mc.Method5("bb");     结果为:2222222