作用:可以将一个方法的实现写在2个文件中。
作用主要是:
1。提供一个比预处理更“干净”的方式
2。提供简单的代理-事件模型
3。提供“虚方法”的的另外一个版本
示例:
file1.cs:
using System;
using System.Collections;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace TestCS
{
partial class c1
{
//必须定义在partial的类中的,定义为partical的method
//必须返回void
//也可以是静态方法
partial void onSayHello(string msg);
public bool TestMethod(string msg)
{
onSayHello(msg);
return true;
}
}
class Program
{
static void Main(string[] args)
{
c1 c = new c1();
c.TestMethod("It's good day");
}
}
}
file2.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestCS
{
partial class c1
{
//必须定义在partial的类中的,定义为partical的method
//必须返回void
//也可以是静态方法
partial void onSayHello(string msg)
{
Console.WriteLine("xx====" + msg);
}
}
}