Пример #1
0
        public event EventHandler <IncrementerEventArgs> CountedADozen;//创建事件

        public void DoCount()
        {
            IncrementerEventArgs args = new IncrementerEventArgs();

            for (int i = 0; i < 100; i++)
            {
                if (i % 12 == 0 && CountedADozen != null)
                {
                    args.IterationCount = i;
                    CountedADozen(this, args);
                }
            }
        }
Пример #2
0
 private void Incrementer_CountedADozen(object source, IncrementerEventArgs e)//声明事件处理程序
 {
     Console.WriteLine("Incremented at iteration: {0} in {1}", e.IterationCount, source.ToString());
     DozensCount++;
 }