there are several conditions for determining whether a method constitutes an overload:
In the same class;
The method name is the same;
The argument list is different.
you should be aware of the issues when designing overloaded methods
1 avoid arbitrarily changing the name of the parameter in the overload. If one of the overloads of an overload represents the same input as a parameter of another overload, the two arguments should have the same name.
For example, do not perform the following actions:
Copy Code code as follows:
public void Write (string message, FileStream stream) {}
public void Write (string line, FileStream File,bool closestream) {}
The correct definitions of these overloads are shown below
Copy Code code as follows:
public void Write (string message, FileStream stream) {}
public void Write (String message, FileStream Stream,bool closestream) {}
Maintains sequential consistency of overloaded member parameters. In all overloads, the position of the same parameter should be the same.
For example, do not perform the following actions:
Copy Code code as follows:
public void Write (string message, FileStream stream) {}
public void Write (FileStream stream, String message, bool Closestream) {}
The correct definitions of these overloads are as follows:
Copy Code code as follows:
public void Write (string message, FileStream stream) {}
public void Write (String message, FileStream Stream,bool closestream) {}
The above two kinds of writing structure is clear, enhances the readability of the code, more suits the specification.
This guideline has two constraints:
If the overload takes a variable argument list, the list must be the last parameter.
If the overload takes an out parameter, by convention, such parameters should be the last argument
If extensibility is required, the longest overload is used as a virtual overload. A shorter overload should only step through a longer overload.
the difference with override rewrite
Override refers to the inheritance of methods between a parent class and a subclass that have the same name and parameter type.