O'Reilly logo

From Java to C#: A Developer's Guide by Heng Ngee Mok

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

15.3. A full example

After examining the various pieces of the whole picture, it is time to put them all together. Here is a fully coded example consisting of three classes – the source, the consumer, and an execution class containing the Main()method. To keep things simple, I am not going to write a custom-made subclass of EventArgs for the event object, and I have purposely placed the Main() method in a separate class so that the role of each class can be clearly seen.

Lines 1 – 7 code the delegate declaration:

1:  using System;
2:
3:  /* -----------------------------------------------
4:   * Delegate declaration
5:   *--------------------------------------------- */
6:  delegate void MyEventHandler (object sender, EventArgs e);
7:

Lines 8 – 29 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required