鼠类:

public class Mouse
{
public string Name { get; set; }
public Mouse(Cat cat)
{
cat.Scream += new Cat.ScreamEventHandler(cat_Scream);
cat.Scream += this.RunAway;
}
public void RunAway(object sender, ScreamEventArgs e)
{
Cat c = (Cat)sender;
Console.WriteLine("{0} coming,she said:"{1}",{2} running!(Running...)", c.Name, e.Msg, this.Name);
}
void cat_Scream(object sender, ScreamEventArgs e)
{
Cat c = (Cat)sender;
Console.WriteLine("{0} coming,she said:"{1}",{2} running!", c.Name, e.Msg, this.Name);
}
}

  这里的委托定义和.net Framework 类库定义方式相同,有助于了解系统提供的委托机制,所以还有一个猫叫事件的参数类:

public class ScreamEventArgs
{
public readonly string Msg;
public ScreamEventArgs(string msg)
{
this.Msg = msg;
}
}