What is overloading in .net?

藏色散人
Release: 2020-09-10 13:53:33
Original
2816 people have browsed it

Overloading in

What is overloading in .net?

.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)
{
}
Copy after login

2)

float Max(float i,float j)
{
}
Copy after login

In your program

int i,j,k;
k=Max(i,j);//将调用第一个Max
float x,y,z;
z=Max(x,y);//将调用第二个Max
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!