public delegate void CatListeningHandler();
class Cat
{
public event CatListeningHandler CatCry;
public void Cry()
{
Console.WriteLine("Meow~~~");
OnCry();
}
protected virtual void OnCry()
{
if (CatCry != null)
{
CatCry();
}
}
}
class Mouse
{
public void Run()
{
Console.WriteLine("Mouse run away……");
}
}
class Program
{
static void Main(string[] args)
{
Cat obj_cat = new Cat();
Mouse obj_mouse = new Mouse();
obj_cat.CatCry += new CatListeningHandler(obj_mouse.Run);
obj_cat.Cry();
Console.ReadLine();
}
}