1 class 参数 2 { 3 public void doSome(string str,params int[] values){ 4 if (values != null && values.Length > 0) 5 { 6 for (var i = 0; i < values.Length; i++) 7 { 8 Console.WriteLine(str + "," + values[i]); 9 }10 }11 else {12 Console.WriteLine(str);13 }14 }15 static void Main() {16 参数 c = new 参数();17 c.doSome("a");18 c.doSome("b",1);19 c.doSome("c",1,2,3);20 int[] arr = { 1, 5, 7 };21 c.doSome("d",arr);22 }23 }
执行结果:
新闻热点
疑难解答