I am trying the understand the need for Events when Custom Delegates can directly invoke the list of methods added to the invocation list.
I apologize if the question is too dumb but this is something I was trying to understand for a long time.
I am trying the understand the need for Events when Custom Delegates can directly invoke the list of methods added to the invocation list.
I apologize if the question is too dumb but this is something I was trying to understand for a long time.
They are essentially the same yes, but the simple difference is that delegates can be invoked from any scope (visibility permitting), but an event can only be invoked by a member on the class that declares it.
If you use a delegate without making sure it's an event. It means that users of your class can simply set their delegate. The next one to do that will basically clear the previous one.
When you use events the user can only "join" using += EventHandler
and can't use = EventHandler
Another thing about events, is that they prevent users from calling the delegates. The only thing they can do is register themselves.