c#的params参数使用示例_C#教程

分享到:


class 参数
    {
        public void doSome(string str,params int[] values){
            if (values != null && values.Length > 0)
            {
                for (var i = 0; i < values.Length; i++)
                {
                    Console.WriteLine(str + "," + values[i]);
                }
            }
            else {
                Console.WriteLine(str);
            }
        }
        static void Main() {
            参数 c = new 参数();
            c.doSome("a");
            c.doSome("b",1);
            c.doSome("c",1,2,3);
            int[] arr = { 1, 5, 7 };
            c.doSome("d",arr);
        }
    }

昵    称:
验证码:

相关文档: