Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What is the difference between Event and Delegates. In lots of places we have to faced this question. But not from every sites we got right answer.
Posted
Comments
Volynsky Alex 8-Aug-12 18:58pm    
Please read following articles:
http://forums.iis.net/p/1174735/1967915.aspx
http://www.codeproject.com/Articles/12043/Using-Events-and-Delegates-in-C
http://www.csharp-station.com/Tutorial/CSharp/lesson14

I think going through this article is well worth the time: Events and Delegates simplified[^].
 
Share this answer
 
Comments
Prasad_Kulkarni 25-May-12 0:54am    
My 5! Nice article..
Wendelius 31-May-12 14:12pm    
Thanks :)
VJ Reddy 25-May-12 6:35am    
Good reference. 5!
Wendelius 31-May-12 14:12pm    
Thanks :)
Monjurul Habib 26-May-12 15:49pm    
5!
That's right, good explanation is hard to find, but you can infer the answer by thorough consideration of syntax, functional language description and perhaps probing them in programming.

Roughly speaking, the event instance is a special kind of delegate instance equipped with fool-proof limitations and suitable for event processing. (In last clause I used the word "event" in two different meaning, as a .NET object and as a concept of event-oriented programming in its behavioral aspect.) Also, you should be careful with delegate types and delegate instances — they are not related as a type and its instance. If you examine a delegate instance with Reflection, you will see that its type is some class encapsulating invocation list.

Please see my past answers:
Since we have multicast delegates, why do we need events?[^],
how to call keydown event on particular button click[^],
[Solved] How to add Event for C# Control[^],
A question about usercontrols, nested controls and encapsulation.[^],
WPF : How to Use Event in Custom Control[^],
Delegates and Callbacks[^],
Copying an EventHandler[^],
c# networking windows form[^].

The delegates and delegate instances are explained in depth in my article:
Dynamic Method Dispatcher[^].

Please see the section "4.1 On the Nature of Delegate Instance" referenced above.

—SA
 
Share this answer
 
v2
Comments
Prasad_Kulkarni 25-May-12 0:53am    
Good references +5!
Sergey Alexandrovich Kryukov 25-May-12 1:09am    
Thank you, Prasad.
--SA
VJ Reddy 25-May-12 6:35am    
Nice answer with good references. 5!
Sergey Alexandrovich Kryukov 25-May-12 11:41am    
Thank you, VJ,
--SA
Maciej Los 25-May-12 7:59am    
Good answer, my 5!
Dear Friend,

Hope this will make you clear litte bit.

Delegates and Events Both are related.
Delegates is a function pointer which can able to store the address of any function with same prototype.
Event is a function handler which can handles or run the functions in same prototype of its delegate.
For handling events delegate is uesd.

Regards,
AP
 
Share this answer
 
v2
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 25-May-12 0:40am    
Pure lie. Very inaccurate. I don't mean references of course.
Please see my comments below.
--SA
Prasad_Kulkarni 25-May-12 0:52am    
Then what you actually mean??
Sergey Alexandrovich Kryukov 25-May-12 1:00am    
Sorry, bit event is not a modifier, not in any sense. Where did you even get it?! Just read about it. Event is always a member of some class, like a delegate instance could be. The difference it very subtle.
With delegates, you need to be careful. There are delegate types and delegate instances which are also called delegates. And the type of a delegate instance is not its corresponding delegate type (used in the declaration of a delegate variable or a member). This way, both statements you've done by yourself are incorrect, but your references are adequate and useful.
--SA
Prasad_Kulkarni 25-May-12 1:13am    
I strongly disagree with your comment Pure lie
..and what you've explained here, i'll read it once then get back to you.
Might be I am wrong, but I just answered as I have used it and work'd before. I'll go through it once.
Sergey Alexandrovich Kryukov 28-May-12 19:14pm    
I scratched out these unjust words after your explanation with the link, sorry for that. But I replace it with "very inaccurate" and explained why.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900