What are the necessary conditions for the ASP. NET method to overload?

Source: Internet
Author: User

To determine whether a method constitutes an overload, the following conditions are met:

◆ In the same class;

◆ Method names are the same;

◆ The parameter list is different.

Precautions should be taken when designing the overload method

1. Avoid modifying the parameter name in the overload. If a parameter of one overload is the same as that of another overload, the two parameters should have the same name.

For example, do not perform the following operations:
Copy codeThe Code is as follows:
Public void Write (string message, FileStream stream ){}
Public void Write (string line, FileStream file, bool closeStream ){}

The correct definitions of these reloads are as follows:
Copy codeThe Code is as follows:
Public void Write (string message, FileStream stream ){}
Public void Write (string message, FileStream stream, bool closeStream ){}

Maintain the order consistency of the overloaded member parameters. In all overload operations, parameters with the same name must be in the same position.

For example, do not perform the following operations:
Copy codeThe Code is as follows:
Public void Write (string message, FileStream stream ){}
Public void Write (FileStream stream, string message, bool closeStream ){}

The correct definitions of these reloads are as follows:
Copy codeThe Code is as follows:
Public void Write (string message, FileStream stream ){}
Public void Write (string message, FileStream stream, bool closeStream ){}

The above two statements have a clear structure and enhance the readability of the Code, making them more suitable for standardization.

This criterion has two constraints:

If the variable parameter list is used for overloading, the list must be the last parameter.

If the out parameter is used for heavy load, such parameters should be used as the final parameter according to the Conventions.

If you need scalability, use the longest overload as the virtual overload. A shorter overload must be called gradually.

Differences from override Rewriting

Override refers to the inheritance relationship between the parent class and the Child class. These methods share the same name and parameter type.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.