If I have two methods in the same class of the same name, do the parameters help to differentiate the methods from each other to avoid conflict?
i.e.
Class1
{
void CompareInput(Form1 frm) { }
void CompareInput(Form2 frm) { }
}
If I have two methods in the same class of the same name, do the parameters help to differentiate the methods from each other to avoid conflict?
i.e.
Class1
{
void CompareInput(Form1 frm) { }
void CompareInput(Form2 frm) { }
}
Yes, it is called Overloading:
interface ITest
{
void F(); // F()
void F(int x); // F(int)
void F(ref int x); // F(ref int)
...
int F(string s); // F(string)
...
}
The idea is that the compiler picks up the right function basing on the types of its arguments.
For instance, the following code would call two different functions:
ITest test = // get interface
test.F(0);
test.F("string");
Yes. The differentiation is done by the types of the parameters and is called Member Overloading (aka Method Overloading):
A member's signature includes its name and parameter list. Each member signature must be unique within the type. Members can have the same name as long as their parameter lists differ. When two or more members in a type are the same kind of member (method, property, constructor, and so on) and have the same name and different parameter lists, the member is said to be overloaded ..
The actual method to use is chosen based upon the parameter list types and the type of the arguments applied at the call/usage-site.
In general the "best" selection is chosen, and examples can be found readily (eg. Overloaded method selection logic) for specific cases. If no matching signature is found a compiler error will be raised.