参数类型params
params参数练习
1 namespace Test 2 { 3 class Program 4 { 5 static void Main(string[] args) 6 { 7 //params 构造函数声明数组,可变数组长度 8 UseParam1(4,2,3); 9 UserParam2(2,'b',"hello"); 10 Console.ReadKey(); 11 } 12 public static void UseParam1(params int[] list) //int类型 13 { 14 for (int i = 0; i < list.Length; i++) 15 { 16 Console.Write(list[i]+" "); 17 } 18 Console.WriteLine(); 19 } 20 public static void UserParam2(params object[] list) //object类型 21 { 22 for (int i = 0; i < list.Length; i++) 23 { 24 Console.Write(list[i]+" "); 25 } 26 } 27 28 } 29 }