purpose of 'event' keyword?

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

C# newbie here.... studying about delegates and now events.

I just don't get the purpose of declaring events using the event keyword.
What does this do for me that can't be done using only delegates?
 
Wow - what a great newsgroup. I got two questions answered within two hours
of posting.

Thanks for the link to the past thread, Jose.
 
Hi Bob,

Unlike delegates, with an event, you can only use += or -= to
add or remove event handlers. This ensures that the
existing list of delegates isn't inadvertently deleted by an
event subscriber using the = operator.

Another diffreence being that unlike plain delegates, only the
class that owns the event can invoke/fire the event to the
event handlers.

Regards,
Aravind C
 
Back
Top