C # overload rewrite (override)

Source: Internet
Author: User

A Method signature consists of a method name and a parameter list (the order and type of parameters.

Note: The method signature does not include the return value of the method. Although each overload method can have different return types, a single return type is not enough to distinguish which method is used.

In C #, two or more methods in the same class can have different names, as long as their parameter declarations are different. In this case, this method is called overload. This process is called method overloading ). Method Overloading is one of the most useful features of C.

When a method is called, C # uses the method signature to determine which method to call. Therefore, the parameter list of each overload method must be different. Although each overload method can have different return types, a single return type is not enough to distinguish which method is used. When C # Calls an overloaded method, the method that matches the parameters of the parameter is executed.

 

Override refers to the further improvement of the implementation of the base class method by the derived class.

 

  • You cannot override non-virtual or static methods. The override base method must be virtual, abstract, or override. Why can override be rewritten? Because the override in the base class is actually a rewriting of the base class, because inheritance can be passed, you can also override the override method in the base class.
  • Override declares that the accessibility of the virtual method cannot be changed. The override and virtual methods must have the same access level modifier.
  • You cannot use modifiers new, static, virtual, or abstract to modify the override method.
  • The override attribute declaration must specify the access modifier, type, and name exactly the same as the inherited attribute, and the overwritten attribute must be virtual, abstract, or override.
  •  

    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.