❔ What of use is the keyword "event"
The essence of the event field is just an object of delegate type which will invoke embedded methods when it is invoked like a method, coding below is also ok:
So the question comes.
7 Replies
Is your question why use events instead of just using delegates?
Yeah
An event limits who can call the delegates.
Basically only the publisher can call/raise the event
This won't compile
Because Bar can only subscribe to the event, it can't raise it
Other limits are you can only subscribe/unsubscribe from outside the publisher, you can't really set MyEvent to null for example
Yes you can set it to null in the publisher
So the difference between the delegate object and the event object is whether it can be raised outside the type.
Yes, events are like a special delegates that can't be raised nor set outside of the type/derived type.
Thank u
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.