Team LiB
Previous Section Next Section

Summary

In this chapter, we discussed delegates and events. A delegate is an object that encapsulates some anonymous method by itself. To use a delegate, you should declare it, instantiate it with some method that should be associated with delegate, and then invoke it.

We also discussed what multicast and singlecast delegates are, their internal structure, and the common rules of their use. Multicast delegates are lists of linked delegates that are invoked by turn.

An event is a way for a class to provide notifications to clients of that class when some interesting thing happens to an object. We discussed the step-by-step process of creating and using events. The process comprises the following steps:

  • Delegate declaration

  • Event declaration

  • Declaration of event handlers

  • Event-raising method declaration

  • Registration of event handlers

  • Event raising

Finally, we took a look at the most typical example of event use.

    Team LiB
    Previous Section Next Section