Library tutorials & articles

Events and Delegates

Events

Events are the messages sent by an object to indicate the occurrence of an event. Event can also be defined as a member that enables an object to provide notification. Events provide a very powerful means of inter-process communication. The most familiar example of events are graphical user interface, events are fired when any control is clicked on the GUI.

Events are not used only for graphical user interfaces. Events provide a generally useful way for objects to signal state changes that may be useful to the client of that object. In C# events are used with delegates. If you don’t have through understanding of delegates please refer the above portion. In event communication the event raiser class doesn’t know who is going to handle the event  now the delegates comes into play that acts as an intermediary between the source and the receiver.

// Delegate
public  delegate void newdelegate();

// Event Declaration
public event newdelegate newevent;

We can categories events into two types

  • Customized Events
  • Predefined Events

Comments

  1. 17 Oct 2006 at 10:34
    Good article for beginners.

  2. 01 Jan 1999 at 00:00

    This thread is for discussions of Events and Delegates.

Leave a comment

Sign in or Join us (it's free).

Faisal Jawaid

Related podcasts

  • Object-Oriented Programming in Ruby

    In this episode, I talk with Scott Bellware about object-oriented programming in Ruby, and Ruby's object model. This is taken from a private conversation, and the audio quality suffers at times. Much thanks to Scott for allowing this to be released.This episode of the Alt.NET Podcast is bro...

We'd love to hear what you think! Submit ideas or give us feedback