110,545
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 收衣服
{
public delegate void Mydelegate(); //先定义一个委托类
class me //我
{
public void PickupClothes() //我有一个收衣服的方法
{
Console.WriteLine("衣服收好了!");
}
public void PhoneNeighbor() //我还有一个给邻居打电话的方法
{
Neighbor PLMM = new Neighbor(); //假设邻居是一个漂亮MM~
PLMM.GetPhone += new Mydelegate(PickupClothes); //告诉她怎么收衣服。。。(给getphone事件绑定一个pickupclothes的方法)
PLMM.Doit(); //just do it...
}
}
class Neighbor //邻居
{
public event Mydelegate GetPhone; //邻居有一个接电话的事件
public void Doit() //邻居还要有一个能处理事件的方法
{
if (GetPhone != null) //如果我打电话过来不是啥都没说
{
GetPhone(); //那么就照我说的去做吧!
}
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("下雨了!"); //下雨了。。。
me me = new me(); //实例化一个我
me.PhoneNeighbor(); //给邻居打电话
}
}
}