Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the differences between delegates and events?

What are the differences between delegates and an events? Don't both hold references to functions that can be executed?

like image 287
Sean Chambers Avatar asked Aug 26 '08 23:08

Sean Chambers


People also ask

What is difference between delegate and events in C#?

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.

What is the difference between events and multicast delegates?

Multicast delegates help to invoke multiple callbacks. Events encapsulate delegate and implement publisher and subscriber model.

How are events and delegates related?

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.

What does it mean to be a delegate at an event?

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.


1 Answers

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.

like image 138
mmcdole Avatar answered Sep 26 '22 06:09

mmcdole