----------------------------------------------------------- New Message on BDOTNET
----------------------------------------------------------- From: Ennittum1 Message 20 in Discussion This one is really cute.Very good one ! Thanks man. -----Original Message----- From: Varad_RS [mailto:[EMAIL PROTECTED] Sent: Friday, September 24, 2004 8:52 AM To: AhmedabadUserGroup; BDotNet; ChennaiNetUserGroup; DotNetSIG; dotnetusergroupHyd; MSDotNetIndore; MumbaiUserGroup Subject: Re: Varad's .NET Info New Message on BDOTNET Varad's .NET Info Reply Reply to Sender Recommend Message 19 in Discussion From: Varad_RS #) Delegate: A neat example! Suppose your daughter is grounded: she's not allowed to use the phone. If she picks up the phone, both mom and dad want to know about it. Slap this code on her and she could wind up in big trouble! using System; namespace Grounded { class Mother { public void subscribe() { Console.WriteLine("Mother Subscribing"); Daughter.onPhoneCall += new Daughter.OnPhoneCallHandler(Notify); } public void Unsubscribe() { Console.WriteLine("Mother Unsubscribing"); Daughter.onPhoneCall -= new Daughter.OnPhoneCallHandler(Notify); } public void Notify() { Console.WriteLine("Mother Notified"); } } class Father { public void subscribe() { Console.WriteLine("Father Subscribing"); Daughter.onPhoneCall += new Daughter.OnPhoneCallHandler(Notify); } public void Unsubscribe() { Console.WriteLine("Father Unsubscribing"); Daughter.onPhoneCall -= new Daughter.OnPhoneCallHandler(Notify); } public void Notify() { Console.WriteLine("Father Notified"); } } class Daughter { public delegate void OnPhoneCallHandler(); public static event OnPhoneCallHandler onPhoneCall; public void PlaceCall() { Console.WriteLine("Daughter placed call"); if(onPhoneCall != null) { onPhoneCall(); } } } class Class1 { static void Main(string[] args) { Father f = new Father(); Mother m = new Mother(); Daughter d = new Daughter(); m.subscribe(); f.subscribe(); d.PlaceCall(); m.Unsubscribe(); f.Unsubscribe(); d.PlaceCall(); } } } Happy C# Coding! Regards, Varad Microsoft Solutions Group Satyam Computer Services LTD., View other groups in this category. ----------------------------------------------------------- To stop getting this e-mail, or change how often it arrives, go to your E-mail Settings. http://groups.msn.com/BDotNet/_emailsettings.msnw Need help? If you've forgotten your password, please go to Passport Member Services. http://groups.msn.com/_passportredir.msnw?ppmprop=help For other questions or feedback, go to our Contact Us page. http://groups.msn.com/contact If you do not want to receive future e-mail from this MSN group, or if you received this message by mistake, please click the "Remove" link below. On the pre-addressed e-mail message that opens, simply click "Send". Your e-mail address will be deleted from this group's mailing list. mailto:[EMAIL PROTECTED]
