How to add parameters to same functions?
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.
精彩评论