C# delegates and events

Question posted in Computer Software on 06 2010
Rate question difficulty level 1 Votes
what are delegates? what are events? how they are connected?
 
 
1 Answer
 
A delegate in C# is similar to a function pointer in C or C++. Using a delegate allows the programmer to encapsulate a reference to a method inside a delegate object. The delegate object can then be passed to code which can call the referenced method, without having to know at compile time which method will be invoked.

The Event model in C# finds its roots in the event programming model that is popular in asynchronous programming. The basic foundation behind this programming model is the idea of "publisher and subscribers." In this model, you have publishers who will do some logic and publish an "event." Publishers will then send out their event only to subscribers who have subscribed to receive the specific event.

In C#, any object can publish a set of events to which other applications can subscribe. When the publishing class raises an event, all the subscribed applications are notified. The following figure shows this mechanism.

06/24/2010
 
 
Add an answer*
 
Your name
Email
 
Company: TGS
Location: Israel
C# Delefates.Events

add a question

arrow_blue


Now hiring!