Asp. net method How to overload the prerequisites

Source: Internet
Author: User
Tags bool

  Many novice friends do not know how to overload the ASP.net method, the following is introduced in the design of overloaded methods should pay attention to matters, interested friends do not miss

Determining whether a method constitutes an overload has several conditions:    in the same class;    method names are the same;    argument lists.     When designing overloaded methods you should pay attention to things     1 Avoid changing the name of the parameter in the overload arbitrarily. If one of the overloads of an overload represents the same input as a parameter of another overload, the two arguments should have the same name.     For example, do not perform the following Operation:  code as follows: public void write (string message, FileStream stream) {}  public void write (str ing line, FileStream file,bool closestream) {}    The correct definition of these overloads is as follows   code as follows: public void Write (String message, Fil eSTREAM stream) {}  public void Write (String message, FileStream stream,bool closestream) {}    Maintains sequential consistency of overloaded member parameters. In all overloads, the position of the same parameter should be the same.     For example, do not perform the following Operation:  code as follows: public void write (string message, FileStream stream) {}  public void Write (Fil eSTREAM stream, String message, bool Closestream) {}    The correct definition of these overloads is as follows:  code: public void Write (string Messa GE, FileStream stream) {}  public void Write (String message, FileStream stream,bool closestream) {}    both The method structure is clear, enhances the readability of the code, is more suitable for the specification.     This guideline has two constraints:  &nbsp If the overload takes a variable argument list, the list must be the last parameter.     If the overload takes out parameters, by convention, such parameters should be used as the last parameter     If extensibility is required, the longest overload is used as a virtual overload. A shorter overload should only step through a longer overload. The difference between     and override overrides     override refers to the inheritance of methods between the parent class and the subclass, which have 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.