partial 部分类

partial 关键字允许把类、结构、方法或接口放在多个文件中。一般情况下,一个类全部驻留在单个文件中。但有时,多个开发人员需要访问同一个类,或者某种类型的代码生成器生成了一个类的某部分,所以把类放在多个文件中有益。

partial关键字的用法是:把partial放在class、struct或interface关键字的前面。

 

 1 partial class MathTest
 2 {
 3 
 4 public string GetNames(string name)
 5 {
 6 return "first -" + name;
 7 }
 8 }
 9 partial class MathTest
10 {
11 public int value;
12 
13 public int GetSquare()
14 {
15 return value * value;
16 }
17 
18 public static int GetSquareOf(int x)
19 {
20 return x * x;
21 }
22 public static double GetPi()
23 {
24 return 3.1415926;
25 }
26 }
View Code

 

posted @ 2016-10-08 14:47  指间的徘徊  阅读(158)  评论(0编辑  收藏  举报