Why do we use an event?

I got a bit confused here. I mean C# delegate works fine, isn’t it? So what’s the difference between event and delegate?

events are a protection over pure delegates, preventing antipatterns (like obj.RiseMyEvent()) and accidental clearing of registered event handlers.

I’ve skipped most of the latest 2 chapters because i’m already a professional C# programmer and those chapters where mostly about basic c# stuffs, but I’ve heard some chunk of explaination in the video too about why using events. Anyway if you want to dive into more details, you can find informations on official c# documentation or briefly googling, like this useful article:

Consider: if you have something that prevent you from doing a mistake writing code (that then would cause you to spend time finding nasty bugs) then why not using it?


Privacy & Terms