开发者

How to add parameters to same functions?

开发者 https://www.devze.com 2023-01-09 22:09 出处:网络
I have text files with one source and two destination path..I\'m sending those to one function called Copy(source,destination).... for one path it c开发者_如何转开发reates(destination).I want to send

I have text files with one source and two destination path..I'm sending those to one function called Copy(source,destination).... for one path it c开发者_如何转开发reates(destination).I want to send the other parameter(other destination path)...How can i achieve this?


You could create an overload of the function to take multiple destination paths, and all it does it iterate all the destination paths and call the original Copy function:

public void Copy(string sourcePath, params string[] destinationPaths)
{
    foreach (string destPath in destinationPaths) 
    {
        Copy(sourcePath, destPath);
    }
}

You can call this with:

Copy(sourcePath, destinationPath1 [, destinationPath 2, destinationPath 3...]);

or you could just call Copy(source, dest) twice.

0

精彩评论

暂无评论...
验证码 换一张
取 消