C# --- Just a quick lesson on Overloading a function and related questions.
Posted on 2005-03-15
I was wondering... I've read some on overloading but had just a quick set of questions.
I am simply looking to create a method/function that can take different Params/arguments. So...
Do I need to re-write the whole function/method like this
public void MyFunction(string MyStringInput, bool myBool)
public void MyFunction(string MyStringInputArray, bool myBool)
I understand that which ever best overload is picked based on the types passed in but...
1) Do I need 2 independant and separate functions/methods for an overload or can I just use one? For example if the "Code here" inside the function is written to handle either type of "type thats passed in, is there a way to just overload using one function, i.e., something like...
public void MyFunction(string MyStringInput | string MyStringInputArray, bool myBool)
or is there no way around having 2 different functions with the same name, and almost duplicate code?
Let me thank you in advance and sorry for the seemingly trivial nature of my question.
Hope all is well in your world.