3 ms·
Ask HN: Understanding C# Events
Hello -
I have been trying to understand the purpose/reason behind C# events. I understand that a delegate is basically a function pointer. But all of the examples I have seen so far explaining events seem complicated and assume a certain level of understanding (Observer pattern).
I do realize Visual Studio creates Events for you, but I prefer to really understand something before using it. So I have been trying to comprehend the practical application of events.
As I mentioned, there are several websites that I had read which provided "simplified" examples, but even those lead me to think, "I see what this person is doing, but I still don't understand why this is being done using events."
Any easy to understand examples using an event in a practical manner that you can recommend?
Thanks for your help!
- IanDrake 14y agoCan't think of a good article, but here's my take: Delegate == singlecast. Meaning it can only point to one function at one time. Calling the delegate calls the assigned function. Event == multicast. Meaning an event is essentially as list of delegates. When the event is fired, each delegate is called synchronously in the order they were added. That is the functional difference. Hope that helps.
- leviccampbell 14y agohttp://stackoverflow.com/questions/803242/understanding-events-and-event-handlers-in-c-sharp http://stackoverflow.com/questions/803242/understanding-even...