天天看點

方法可變參數

static void main(string[] args)

{

//string[] str =

{ "", "" };

//testparams(str);

//testparams("我","愛","北京","天安門!");

//testparams();

console.writeline("你好{0},{1},{2},{3},{4}","1","2","3","4","5");

console.readkey();

}

//1. params隻能用來修飾方法的參數 參數必須是1個1維數組

//2. 參數清單中最多隻能出現1個可變參數

并且必須要在參數清單的最後1個.不能有預設值.

//3. 調用的時候 因為參數是1個數組類型的 是以可以傳1個數組.

//4. 在調用的時候 還可以直接參數數組的元素

//5. 如果可變參數的長度是0 表示調用者沒有為他傳遞任何元素.

public static

void testparams(params string[] strs)

if

(strs.length==0)

//foreach (string str in strs)

//{

// console.writeline(str);

//}