using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 利用委托实现回调
{
class Program
{
static void Main(string[] args)
{
}
public delegate void ShowTimeDelegate();
class A
{
public void AShowTime() { }
}
class B
{
public static void BShowTime() { }
}
//实例关键controller类
class Controller
{
private ShowTimeDelegate d;//用于接收外界对象提供方法,以实现回调
public void RegisterDelegateForCallback(ShowTimeDelegate method)
{
d += method;//外界对象将需要回调的方法传入
}
public void UnReginterDelegareForCallback(ShowTimeDelegate method)
{
d -= method;//移除要回调的方法
}
public void CallBack()
{
if (d != null)
{
d.Invoke();//调用所有需要回调的方法
}
}
}
}
}