Tutorial :How to add parameters to same functions?



Question:

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 creates(destination).I want to send the other parameter(other destination path)...How can i achieve this?


Solution:1

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.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »