C # BASIC language knowledge (5): Partial Class Classification

Source: Internet
Author: User

Partial class, Category or distribution class. As the name implies, a class is divided into multiple parts. For example, a class has three methods. In VS 2005, three methods in the class are stored in three different. CS files.
Benefits:
1. A large project class can be divided into different blocks and written by different programmers at the same time.
2. if the source is automatically generated by the system, you can add it with an independent partial class without having to change it to the original class.
3. When a class is large, you can use partial class for functional division, which is also a good classification method.

If you are developing a project's public function library, the richer the content for the public function library, the better, but it cannot be written at once. You need to accumulate at, then you can use partial class, upload the newly developed partial class program to the server or a specific directory at intervals. instead of copying and pasting the new code into the original program code, reduce unnecessary troubles.

Example: Define the example class as partial class, and define the three methods M1, M2, and m3 of the class in the example1.cs, example2.cs, and example3.cs class files respectively, and then in the partialclass. aspx. instantiate the example class in Cs and call the methods in the class.

 1     //Example1.cs 2     public partial class Example 3     { 4         public string m1() 5         { 6             return "Method 1 "; 7         } 8     } 9 10     //Example2.cs11     public partial class Example12     {13         public string m2()14         {15             return "Method 2 ";16         }17     }18 19     //Example3.cs20     public partial class Example21     {22         public string m3()23         {24             return "Method 3 ";25         }26     }

 

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.