1. First explain what is method overloading?
Method overloading refers to a technique in which a method with the same name in the same class, with different parameters, chooses to perform an operation on the method that matches the argument, in the form of an argument.
The different parameters mentioned here refer to the following situations:
① parameter types are different
The number of ② parameters is different
The number of ③ parameters is the same as their order of precedence.
Note: The system will consider two cases of the same method, so that the two methods can not be in the same class, or the system will error.
⑴ return types, two methods with the same method name and number of arguments, order, and type
⑵ return type is the same, the method name and parameter number, order, type are the same two methods, but the name of the parameter is different
For example:
①protected void A ()
{
Console.WriteLine ("Aaaaaaaaaaaa");
}
②protected void A (string s, int a)
{
Console.WriteLine ("CCCCCCCCCCC");
}
③protected void A (string a, int s)
{
Console.WriteLine ("CCCCCCCCCCC");
}
④protected void A (int a,string s)
{
Console.WriteLine ("BBBBBBBBBB");
}
①, ②, ④ are method overloads, and ①, ③, and ④ are method overloads;
② and ③ are the same method because they are just different names of parameters.
2. Scope of application: Common method and construction method can be
3. Determining whether a method constitutes an overload has the following conditions:
In the same class;
Method name is the same;
The parameter list is different.
Overloading of C # methods