Hi all,
I'm trying to make some overloads of some of my methods in my "toolbox" library. I have a method called ProcCheck that I want to be able to use with these overloads:
public static bool ProcCheck(string processName)
{
return ProcCheck(processName, "", "");
}
public static bool ProcCheck(string processName, string userName)
{
return ProcCheck(processName, userName, "");
}
public static bool ProcCheck(string processName, string machineName)
{
return ProcCheck(processName, "", machineName);
}
This will obviously not compile since two of the signatures are identical. My question is: What is a good way to achieve these two overloads without simply renaming one of them?

2 answers
In versions of .NET up to 3.5, the only sensible approach IMO is to accept that the third overload isn't feasible and that you'll therefore have to call ProcCheck(processName, "", machineName) directly.
In .NET 4.0, you could use optional parameters to combine ALL the overloads into one:
answered one year ago by:
17279
2499
Well isn't that handy :) Now all that's left is to convince my manager that I need Visual Studio 2010 for this xD
17279
If you're writing a library for other people to use, then I wouldn't use optional parameters anyway. They're not CLS compliant and, if you change the default values, client programs need to be recompiled. The main reason they were introduced is to facilitate COM or Office interop which is now hugely simplifed compared to what we had to do before :)
2499
I see. I was planning on using it for my own "toolbox" DLL so that wouldn't be a problem. However, I think I'll stick with renaming some of the overloads for now :)
753
IF you willing to use vs2010 express it should be ok.
Here is another method of doing it.
extending DotNets string rather
1. create a class like so
you can use this class like so
answered one year ago by:
753