Definition: When there are two members accessible from the same class with the same name but different signatures.
int String.IndexOf (String name); int String.IndexOf (String name, int startIndex);
1: MethodInfo Type.GetMethod(String name); //ignoreCase = false 2: MethodInfo Type.GetMethod (String name, boolean ignoreCase);
It is very common to use a zero’ed state for the default value (such as: 0, 0.0, false, “”, etc).
It's common to have a set of overloaded methods with an increasing number of parameters to let the developer specify a desired level of information. The more parameters specified, the more detail that is specified. All the related methods have a consistent parameter order and naming. Each of the method variations has the same semantics for their shared set of parameters.
public class Foo { readonly string defaultForA = "default value for a"; readonly string defaultForB = "default value for b"; readonly string defaultForC = "default value for c"; public void Bar() { Bar(defaultForA, defaultForB, defaultForC); } public void Bar(string a) { Bar(a, defaultForB, defaultForC); } public void Bar(string a, string b) { Bar(a, b, defaultForC); } public void Bar(string a, string b, string c) { // core implementation here } }
This consistency is present even if the parameters have different types.
The only method in such as a group that may be virtual is the one that has the most parameters.
Where it is appropriate to have variable numbers of parameters to a method, use the convention of declaring N methods with increasing numbers of parameters, and also provide a method which takes an array of values for numbers greater than N. N=3 or N=4 is appropriate for most cases. For example:
public class Foo { public void Bar(string a) { Bar(new string[] {a}); } public void Bar(string a, string b) { Bar(new string[] {a, b}); } public void Bar(string a, string b, string c) { Bar(new string[] {a, b, c}); } public void Bar(string[] args) { // core implementation here } }