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 }
View Code