public delegate void SalaryCompute(); //声明一个代理类
public class Employee
{
public event SalaryCompute OnSalaryCompute; //定义事件,将其与代理绑定
public virtual void FireEvent() //触发事件的方法/
{
if (OnSalaryCompute != null)
{
OnSalaryCompute(); //触发事件
}
}
}
class Program
{
static void Main(string[] args)
{
Employee ep = new Employee();
Program pr = new Program();
ep.OnSalaryCompute += new SalaryCompute(pr.SalaryHandler);
ep.FireEvent();//触发事件
Console.ReadLine();
}
public void SalaryHandler()
{
Console.WriteLine("Salary... ...");
}
}