public void DoCount() { // Object of custom class. IncrementerEventArgs args = new IncrementerEventArgs(); for (int i = 1; i < 100; i++) { args.IterationCount = i; if (i % 12 == 0 && CountedADozen != null) { // Pass parameters when raising the event. CountedADozen(this, args); } } }
// The signature of the event handler must match that of the delegate. void IncrementDozensCount(object source, IncrementerEventArgs e) { Console.WriteLine("Incremented at iteration: {0} in {1}", e.IterationCount, source.ToString()); DozensCount++; }