Why do we need the "event" keyword while defining events ?
Posted
by Puneet Dudeja
on Stack Overflow
See other posts from Stack Overflow
or by Puneet Dudeja
Published on 2010-06-12T12:55:38Z
Indexed on
2010/06/12
13:02 UTC
Read the original article
Hit count: 227
I don't understand why do we need the "event" keyword while defining events, when we can do the same thing without using "event" keyword, just by using the delegates.
e.g.
public delegate void CustomEventHandler(int a, string b);
public event CustomEventHandler customEvent;
customEvent += new CustomEventHandler(customEventHandler);
customEvent(1,"a"); // Raising the event
Here if I remove the "event" keyword from the second line, then also I can raise the event by invoking the delegate. Can anybody please tell me why is this event keyword needed ?
© Stack Overflow or respective owner