namespaceDelegate_Event{classPublisher{publicdelegatevoidPublishMsgDelegate(stringmsg);publicPublishMsgDelegatepublishMsg=null;publicvoidpublish(stringmsg){publishMsg(msg);}}classSendViaEmail{publicvoidsendMsg(stringmsg){Console.WriteLine(msg+" sent via email");}}classSendViaSMS{publicvoidsendMsg(stringmsg){Console.WriteLine(msg+" sent via SMS");}}classMainClass{publicstaticvoidMain(string[]args){Publisherpub=newPublisher();SendViaEmailse=newSendViaEmail();SendViaSMSsm=newSendViaSMS();pub.publishMsg+=se.sendMsg;pub.publishMsg+=sm.sendMsg;pub.publish("hello world");}}}
classSendViaEmail{publicvoidsendMsg(stringmsg){Console.WriteLine(msg+" sent via email");}publicvoidsubscribe(Publisherpub){pub.publishMsg+=sendMsg;}}classSendViaSMS{publicvoidsendMsg(stringmsg){Console.WriteLine(msg+" sent via SMS");}publicvoidsubscribe(Publisherpub){pub.publishMsg+=sendMsg;}}classMainClass{publicstaticvoidMain(string[]args){Publisherpub=newPublisher();SendViaEmailse=newSendViaEmail();SendViaSMSsm=newSendViaSMS();se.subscribe(pub);// sm.subscribe (pub);pub.publish("hello world");}}
namespaceDelegate_Event{classPublisher{publicdelegatevoidPublishMsgDelegate(stringmsg);publiceventPublishMsgDelegatemessageEvent=null;publicvoidpublish(stringmsg){messageEvent(msg);}}classSendViaEmail{publicvoidsendMsg(stringmsg){Console.WriteLine(msg+" sent via email");}publicvoidsubscribe(Publisherpub){pub.messageEvent+=sendMsg;}}classSendViaSMS{publicvoidsendMsg(stringmsg){Console.WriteLine(msg+" sent via SMS");}publicvoidsubscribe(Publisherpub){pub.messageEvent+=sendMsg;}}classMainClass{publicstaticvoidMain(string[]args){Publisherpub=newPublisher();SendViaEmailse=newSendViaEmail();SendViaSMSsm=newSendViaSMS();se.subscribe(pub);sm.subscribe(pub);pub.publish("hello world");}}}