//显示器方法 public void ShowMsg(object sender, Heater.BoilEventArgs e) { Heater heater = (Heater)sender; //访问heater类中属性 Console.WriteLine("显示器:热水器的产地:{0}", heater.area); Console.WriteLine("显示器:热水器的型号:{0}", heater.type); Console.WriteLine("显示器:热水器当前温度:{0}", e.temperature); }
static void Main(string[] args) { Heater heater = new Heater(); Alarm alarm = new Alarm(); Display display = new Display(); //注册方法 heater.Boil+= alarm.MakeAlert; heater.Boil += display.ShowMsg; Console.WriteLine("开始执行"); heater.BoilWater(); Console.Read(); }