Register
Sign In
Skip over navigation
Home
Add New Question
Jobs
Products
C# delegates and events
Question posted
in
Computer Software
on
06 2010
Rate question difficulty level
5
1 Votes
what are delegates? what are events? how they are connected?
Add an answer
Share
|
1 Answer
Gadi Berqowitz
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
Enter the code shown above:
please wait..
Company:
TGS
Location:
Israel
Tags:
C#
,
Delefates.Events
Occupations:
Software\System Architecture
,
Software\Web Development
add a question
Now hiring!
Jobs
by
Simply
Hired
View all jobs