public static void Main() { EventTest e = new EventTest(); /* 实例化对象,第一次没有触发事件 */ subscribEvent v = new subscribEvent(); /* 实例化对象 */ e.ChangeNum += new EventTest.NumManipulationHandler(v.printf); /* 注册 */ e.SetValue(7); e.SetValue(11); Bridegroom bridgeroom = new Bridegroom(); Friend friend1 = new Friend("xiaoming"); Friend friend2 = new Friend("xiaohong"); Friend friend3 = new Friend("lisi"); bridgeroom.MarrayEvent += new Bridegroom.MarrayHandler(friend1.SendMessage); bridgeroom.MarrayEvent += new Bridegroom.MarrayHandler(friend2.SendMessage); bridgeroom.MarrayEvent += new Bridegroom.MarrayHandler(friend3.SendMessage); bridgeroom.MarrayEvent -= new Bridegroom.MarrayHandler(friend1.SendMessage); bridgeroom.OnMarriageComing("我要结婚了大家一定要来啊"); Console.ReadKey(); }
public static void Main() { EventTest e = new EventTest(); /* 实例化对象,第一次没有触发事件 */ subscribEvent v = new subscribEvent(); /* 实例化对象 */ e.ChangeNum += new EventTest.NumManipulationHandler(v.printf); /* 注册 */ e.SetValue(7); e.SetValue(11); }