Exemple #1
0
        static void Main(string[] args)
        {
            //发布者类 实例化
            SubClass subClass1 = new SubClass();

            EventSenderClass sender = subClass1;

            // //订阅者类 实例化
            // SubscriberClass sub = new SubscriberClass(sender);
            //
            // //触发事件
            // sender.Start();

            sender.Start();
        }
Exemple #2
0
 public SubscriberClass(EventSenderClass sender)
 {
     //将方法加入事件的委托列表
     sender.KeyPressed += new EventSenderClass.EventHandler <KeyPressedEventArgs>(WhenKeyPressed);
 }