Summary and explanation based on C method overload
- 2020-05-10 18:43:46
- OfStack
1. First, explain 1. What is method overloading?
Method overloading is a technique in which a method with the same name and different parameters in the same class is called to select the method that matches it according to the form of arguments.
The parameter difference here refers to the following situations:
The type of parameter is different
The number of parameters is different
The number of parameters is the same and their sequence is different
Note: the system will consider two cases of the same method, such two methods cannot be in the same class, otherwise the system will report an error.
The method name and the number of parameters, the order, the type are the same
The essay returns two methods of the same type with the same method name and the same number, order, and type of arguments, but with different parameter names
Such as:
1. protected void A(){
Console.WriteLine("aaaaaaaaaaaa"); }
2. protected void A(string s, int a){ // Correct method overloading
Console.WriteLine("ccccccccccc"); }
3. protected void A(string a, int s){
Console.WriteLine("ccccccccccc");
}
(4) protected void A(int a,string s) {
Console.WriteLine("bbbbbbbbbb");
}
and are method overloads
And are the same method, because they are just the names of the arguments. And are the correct method overloading, because they are in a different order
2. Scope of application: both general methods and constructors are acceptable
3. There are several conditions for determining whether a method constitutes an overload:
◆ in the same class;
◆ the method name is the same;
The parameter list is different.