Thursday, February 23, 2006

Unraveling Delegates & Events - The Code Project - .NET

Nice explanation about the difference between delegates and events.



Some properties that Events exhibit:

1) Events can only be invoked by the class that defined it.

2) Events can be included in interfaces whereas interfaces cannot contain fields of type delegate.

3) Events cannot reset the delegate invocation list by using “=” outside its class definitions. Events can only add/remove to the handler by using “+=” and “-=” respectively.
Conclusion:

Including Event modifier to the delegate declaration only lets the adding/removing the target to the invocation list and constraints its invocation from outside the class that defines it.

Unraveling
Delegates & Events - The Code Project - .NET

No comments: