. Net division method

Source: Internet
Author: User

 

    • Division Method
A division class or structure can contain a division method. A part of the class contains the signature of the method. You can define optional implementations in the same or another part. If this implementation is not provided, the method will be removed during compilation and all calls to the method. The division method enables the implementers of a certain part of the class to define methods (similar to events ). The implementers of another part of the class can decide whether to implement this method. If this method is not implemented, the compiler will remove the method signature and all calls to this method. This method is called, including any calculation results in the call, without any impact at runtime. Therefore, anyCodeYou can use the division method at will, even if no implementation is provided. If an unimplemented method is called, it will not cause compilation errors or runtime errors. The division method is particularly useful when you customize the generated code. These methods allow you to retain the method name and signature, so the generated code can call the method, and the developer can decide whether to implement the method. Similar to the Division class, the division method enables the Code created by the Code Generator to work together with the Code created by the developer without running overhead. The division method declaration consists of two parts: definition and implementation. They can be located in different parts of the segmentation class, or in the same part. If there is no implementation declaration, the compiler will optimize the definition Declaration and all calls to the method.
    • Restrictions
      • The partial method declaration must begin with the following keyword partial, and the method must return void.
      • The division method can have the ref parameter, but not the out parameter.
      • The partial method is an implicit private method, so it cannot be a virtual method.
      • The division method cannot be the extern method, because the existence of the subject determines whether the method is defined or implemented.
      • The division method can have static and unsafe modifiers.
      • The division method can be generic. The constraint will be placed on the definition of the division method declaration, but you can also choose to repeat it on the Implementation declaration. The parameter and type parameter names do not need to be the same in the implementation declaration and definition declaration.
      • You can generate a delegate for a defined and implemented branch method, but not for a defined but not implemented branch method.
    • Sample Code
  partial void onnamechanged (); partial void onnamechanged () {} 

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.