C#_ Basics _ Partial class partial (18)

Source: Internet
Author: User

Under the same namespace, you can define only one class of the same class name, for example, there can be only one person class under a namespace.

Partial classes: Understanding that each part is just part of the constituent class, is actually a class, all members are shared, that is, variables defined in a partial class,

In another part of the class can be used, then the variables defined in a partial class, in other parts of the class can not be repeated definition, it is understood to put a class of members, separate into different classes.

Through the case demonstration:

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Threading.Tasks;6 7 namespacePartial Classes8 {9     class ProgramTen     { One         Static voidMain (string[] args) A         { -  -             // the  -  -         } -     } +  -  +     //only one person class can be defined under a namespace, and the Person class section class may be written A     //Partial : A class is made up of some classes, all of which are common and are actually a class at      Public Partial class Person -     { -         Private stringname; -  -         //void Test ()//will be an error, in another part of the class has -         //{ in  -         //} to     } +  -      Public Partial class Person the     { *         //all members are shared, including private members $        //private string name;Panax Notoginseng  -         voidTest () the         { +             //members of other parts of the class can be directly used A Console.WriteLine (name); the         } +     } -      $      Public Partial class Person $     { -        //You can define multiple partial classes -     } the  - Wuyi}

C#_ Basics _ Partial class partial (18)

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.