标签:public
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 委托及事件
{
class Program
{
static void Main(string[] args)
{
Emplyee em = new Emplyee();
Reporter re = new Reporter();
//指明事件触发后,由谁来处理
em.PlayGame+=new DelegateClassHandle(re.Notify);
em.Game();
Console.ReadKey();
}
}
public delegate void DelegateClassHandle(); //定义托管
public class Emplyee //定义员工类
{
public event DelegateClassHandle PlayGame; //定义托管的绑定事件PlayGame
public void Game() //定义一个Game方法
{
if (PlayGame != null) //判断事件是否为空
{
Console.WriteLine("哈哈,开始玩游戏");
PlayGame();
}
}
}
public class Reporter //定义一个报告类
{
public void Notify()
{
Console.WriteLine("报告老板,有人玩游戏");
}
}标签:public
原文地址:http://haixin.blog.51cto.com/1528212/1562548