im new in c#. I know what is delegate (object which collect references of methods) but i dont know what is difference between delegate and event? Why use events and delegates? are there any difference?
-
1[Events and Delegates Simplified](http://www.codeproject.com/Articles/4773/Events-and-Delegates-Simplified) - [Delegates and Events](http://msdn.microsoft.com/en-us/library/orm-9780596521066-01-17.aspx) - Also from Jon Skeet [Delegates and Events](http://csharpindepth.com/Articles/Chapter2/Events.aspx) – Soner Gönül Feb 09 '14 at 17:52
1 Answers
Difference between delegates and events
So what’s really the difference between delegates and events other than the sugar coated syntax of events. The main difference is that event provides one more level of encapsulation over delegates. So when we pass delegates it’s naked and the destination / subscriber can modify the delegate. When we use events the destination can only listen to it.
Summarizing Use of delegates
There are 6 important uses of delegates:- 1. Abstract and encapsulate a method (Anonymous invocation) This is the most important use of delegates; it helps us to define an abstract pointer which can point to methods and functions. The same abstract delegate can be later used to point to that type of functions and methods. In the previous section we have shown a simple example of a maths class. Later addition of new algorithm functions does not affect the UI code.
Callback mechanismMany times we would like to provide a call back mechanism. Delegates can be passed to the destination and destination can use the same delegate pointer to make callbacks.
Asynchronous processingBy using ‘BeginInvoke’ and ‘EndInvoke’ we can call delegates asynchronously. In our previous section we have explained the same in detail.
Multicasting - Sequential processing Some time we would like to call some methods in a sequential manner which can be done by using multicast delegate. This is already explained in the multicast example shown above.
Events - Publisher subscriber modelWe can use events to create a pure publisher / subscriber model.
C# Event Implementation Fundamentals, Best Practices and Conventions

- 344
- 3
- 12