C # 2.0 Sepcification (iii)

Source: Internet
Author: User

(Pick up)

19.4 Incomplete Type

Although maintaining all source code for a type in a single file is a good programming practice, sometimes a type becomes very large and this becomes an impractical limitation. In addition, programmers often use source code generators to produce the initial structure of an application and modify the result code. Unfortunately, when the source code is launched again in the future, the existing changes will be overwritten.

An incomplete type (partial type) allows classes, structs, and interfaces to be split into multiple parts stored in different source files, which is more conducive to development and maintenance. In addition, the incomplete type allows some types of machine-generated parts to be detached from the user-written part, so it is easy to add code generated by the tool.

When you define a type in more than one section, you can use a new type modifier, partial. The following is an example of an incomplete class, which is implemented in two parts. These two parts can be in different source files, for example, because the first part is machine generated from a database mapping tool, and the second part is created by hand.

public partial class Customer{private int id;private string name;private string address;pivate list<order> orders;p Ublic Customer () {...}} public partial class Customer{public void SubmitOrder (order order) {orders. ADD (order);} public bool Hasoutstandingorders () {return orders. count>0;}}

When the previous two sections are compiled together, the result code is the same as the class that was written as a single unit.

public class Customer{private int id;private string name;private string address;pivate list<order> orders;public Cu Stomer () {...} public void SubmitOrder (order order) {orders. ADD (order);} public bool Hasoutstandingorders () {return orders. count>0;}}

All parts of an incomplete type must be compiled together so that the parts can be fused together at compile time. In particular, it is important to note that the incomplete type does not allow the extension of a type that has already been compiled.

The above is C # 2.0 sepcification (three) content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • 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.