What are the differences between delegates and an events? Don't both hold references to functions that can be executed?
Basically, a delegate is just a wrapper around what would be a function pointer in C (or a list of function pointers). An event is an even higher level abstraction that wraps the concept of a delegate together with methods to subscribe and unsubscribe a method to such delegates.
Multicast delegates help to invoke multiple callbacks. Events encapsulate delegate and implement publisher and subscriber model.
Delegate is a type that defines a signature and holds a reference of method whose signature matches with the delegate. Event is a notification raised by an object to signal the occurrence of an action. Delegate is associated with the event to hold a reference of a method to be called when the event is raised.
A delegate is a person who is chosen to vote or make decisions on behalf of a group of other people, especially at a conference or a meeting.
An Event declaration adds a layer of abstraction and protection on the delegate instance. This protection prevents clients of the delegate from resetting the delegate and its invocation list and only allows adding or removing targets from the invocation list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With