static void Main() { Incrementer incrementer = new Incrementer(); Blocks blocks = new Blocks(incrementer); incrementer.DoCount(); Console.WriteLine($"-------------\nTotal hits: {blocks.BlocksCount}"); }
static void Main(string[] args) { Incrementer incrementer = new Incrementer(); Dozens dozens = new Dozens(incrementer); incrementer.DoCount(); Console.WriteLine("Number of dozens = {0}", dozens.DozensCount); }
public Blocks(Incrementer incrementer) { BlocksCount = 0; // 5. registers to be notified when the event occurs // - multiple methods can be registered // - each method must match the delegate signature incrementer.CountedABlock += ShowMessage; incrementer.CountedABlock += ShowAnotherMessage; }
static void Main(string[] args) { Incrementer iObj = new Incrementer(); Dozens dObj = new Dozens(iObj); iObj.DoCount(); Console.WriteLine("Dozen Count: " + dObj.DozensCount); // ----------------------------- Publicsher & Subscriber ---------------------------------- Publisher pObj = new Publisher(); Subscriber s1 = new Subscriber(1); Subscriber s2 = new Subscriber(2); pObj.SimpleEvent += s1.MethodA; pObj.SimpleEvent += s2.MethodA; pObj.SimpleEvent += s2.MethodB; pObj.RaiseTheEvent(); // --------------------------------- System & User (Send notification)------------------------------ System sObj = new System(); User u1 = new User(1); User u2 = new User(2); u1.BildirimAcKapa(sObj); // Baglanti acik u2.BildirimAcKapa(sObj); // Baglanti acik // u1.BildirimAcKapa(sObj); // Baglanti kapali // u2.BildirimAcKapa(sObj); // Baglanti kapali sObj.BildirimGonder("Yarin ders yok"); Console.ReadKey(); }
public Dozens(Incrementer incrementer) { DozensCount = 0; incrementer.CountedADozen += IncrementDozensCount;// Subscribe to the event. }
public Dozens(Incrementer iObj) { DozensCount = 0; iObj.CountedDozen += IncrementDozensCount; }