Partial Class A indicates that this is only part of Class. I can create a class B. CS. Write partial class A in the code. After the program is compiled. The attributes and methods in two A classes are merged and called members of Class.
The New Keyword provided by the partial keyword C #2.0 is used to split the definition of a class, struct, or interface and write it in different source files. Each source file contains a part of the class definition. All parts are combined during compilation of the application. In the following situations, you need to split the classification definition:
1. When processing large projects, assigning a class to multiple independent files allows multiple programmers to process the class at the same time.
2. When using an automatically generated source, you can add the code to the class without re-creating the source file. Visual Studio uses this method when creating Windows Forms and Web Service packaging code. You can create code that uses these classes without editing the files created by Visual Studio.
For example:
In class1.cs:
Namespace vs2012_demo1 {public partial class class1 {public void showmessage1 () {system. Windows. Forms. MessageBox. Show ("111 ");}}}
In class2.cs:
Namespace vs2012_demo1 {public partial class class1 {public void showmessage2 () {system. Windows. Forms. MessageBox. Show ("222 ");}}}
In form1:
Public partial class form1: FORM {class1 class1; Public form1 () {initializecomponent (); class1 = new class1 ();} private void button#click (Object sender, eventargs E) {class1.showmessage1 ();} private void button2_click (Object sender, eventargs e) {class1.showmessage2 ();}}
So
Showmessage1 ()
Showmessage2 () is written in two files. But it belongs to class1.