Delegates are especially used for implementing events and the callback methods. The events are declared and raised in a class and associated with the event handlers using delegates within the same class or some other class. Once you learn how to create and manipulate delegate types, you then. A delegate is a class that encapsulates a method signature. Delegates and events in c journal of object technology. Some other class that accepts this event is called the subscriber class. A delegate is a type safe a function pointer that can reference a method that has the same signature as that of the delegate. Only the class that declares the event can fire it better abstraction. Delegates are method wrappers that can be passed to a code which can invoke wrapped method without any compiletime knowledge of which method will be invoked actually.
The class containing the event is used to publish the event. A delegate is a reference type variable that holds the reference to a method. All of us have been exposed to event driven programming of some sort or the other. This completes the lesson, which was an introduction to delegates and events. You learned how to declare and implement delegates, which provide dynamic runtime method invocation services. In this video we will discuss about raising another custom event from calendarusercontrol. In the subsequent section of this tutorial, we will be looking at this concept with practical examples. One part is publisher that contains definition of events and delegates and another part is subscriber that accepts the event and provides an event handler. The code used in this article can be downloaded from github. Lets write some code using delegates to understand delegates. A collection of registered listeners is notified whenever an event occurs. Watch this tutorial and your confusion will be gone in 30 minutes.
1241 406 187 722 963 150 1381 393 1240 690 1511 1036 715 855 835 752 1273 957 875 199 1444 1121 1109 1233 768 919 900 1297 1069 1478 680 393 394