在C# Function中,要傳遞不同數量的參數可以用 參數 params 與 陣列 來協助

 

static string Combine(params string[] paths){

        string result = string.Empty;

        foreach(string path in paths){

              result = System.IO.Path.Combine(result,path);

        }

        return resulr;

}

 

 

如此 在引用此Function時  就可不限制 參數 數量來使用

 

string fullName = combine(new string[]{"c:\","HStech","Review","Review.exe"});

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 Rh 的頭像
    Rh

    程式狂想曲

    Rh 發表在 痞客邦 留言(0) 人氣()