舉例如下
public partial class Demo {
public int a;
public int b;
}
public partial class Demo {
public void DoSomething() {
System.Console.WriteLine(a + b);
}
}
public partial class Demo {
public void DoSomething2() {
System.Console.WriteLine("There is no spoon.");
}
}
public class DemoTest {
static void Main() {
Demo d = new Demo();
d.a = 11;
d.b = 20;
d.DoSomething();
d.DoSomething2();
}
}
/* 《程式語言教學誌》的範例程式
http://pydoing.blogspot.com/
檔名:class08.cs
功能:示範 C# 程式
作者:張凱慶
時間:西元 2013 年 6 月 */此例的 Demo 類別被分隔成三個部份,編譯執行,結果如下

使用 partial 須注意,一旦類別被宣告為 partial ,此類別所有的分割部份都得宣告為 partial ,不然無法通過編譯。
| 中英文術語對照 | |
|---|---|
| 關鍵字 | keyword |
| 類別 | class |
您可以繼續參考
類別
相關目錄
回 C# 快速導覽
回 C# 教材
回首頁
參考資料
Standard ECMA-334 C# Language Specification
msdn: 部分類別定義 (C# 程式設計手冊)
沒有留言:
張貼留言