示例#1
0
        public event EventHandler <IncrementerEventArgs> CountedADozen; //使用自定义类的泛型委托
        public void DoCount()
        {
            IncrementerEventArgs eventArgs = new IncrementerEventArgs();//自定义类对象

            for (int i = 1; i < 100; i++)
            {
                if (i % 12 == 0 && CountedADozen != null)
                {
                    eventArgs.IterationCount = i;
                    CountedADozen(this, eventArgs);//触发事件
                }
            }
        }
示例#2
0
 void IncrementDozensCount(object s, IncrementerEventArgs e)//处理程序
 {
     DozensCount++;
     Console.WriteLine("Incremented {0} in {1}", e.IterationCount, s.ToString());
 }