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

            //订阅者类实例化
            Dozens dozens = new Dozens(inCrementer);

            //触发事件
            inCrementer.DoCount();

            Console.WriteLine("Number of dozens = {0}", dozens.DozensCount);
        }
Example #2
0
 public Dozens(InCrementer inCrementer)
 {
     DozensCount = 0;
     //订阅事件: 为事件增加处理程序
     inCrementer.CountedADozen += IncrementerDozenscount;
 }