Overloading in
.net means that there are multiple methods with the same name in the same class, but the parameter lists and return value types of these methods are different. It is worth noting that the concept of overloading is not within the scope of object-oriented programming. From the perspective of the compiler, different parameter lists and different return value types mean different method names. In other words, the address of the method is determined at compile time and is a static binding.
From the example, we summarize the basic characteristics of overloading including:
Overloading exists in the same class.
Overloaded methods require the same method name, different parameter lists, and the return value types can be the same or different (a certain degree of return value overloading can be achieved through operator implicit, but it is not recommended).
.NET 2.0 introduces generic technology, so that the same parameter list and the same return value type can also constitute overloading.
Overloading means that several functions have exactly the same name, but different parameter types or numbers. The actual calls will be distinguished by parameter types.
For example, you now have 2 Max functions
1)
int Max(int i,int j) { }
2)
float Max(float i,float j) { }
In your program
int i,j,k; k=Max(i,j);//将调用第一个Max float x,y,z; z=Max(x,y);//将调用第二个Max
Obviously overloading also has polymorphism, But this kind of polymorphism is based on the original code level polymorphism. The above two Max functions have the same name in the text, but after compilation, the internal names are different. Some information such as parameter types must be added. This process is called name compilation. , when compiling the source code that calls Max, the compiler chooses to call the correct Max function based on the parameters when calling in
The above is the detailed content of What is overloading in .net?. For more information, please follow other related articles on the PHP Chinese website!