Events are just a representation of a collection of delegates. You can, if
you want, have a collection of delegates and call them yourself or you can
use the "+=" operator and add delegates to Events. They both achieve the
same thing.
Events are just a representation of a collection of delegates. You can, if
you want, have a collection of delegates and call them yourself or you can
use the "+=" operator and add delegates to Events. They both achieve the
same thing.
Not quite. Events are more limiting to the outside world than
delegates. You can expose an event so that other classes can add and
remove handlers, but not fire the event themselves *or* remove all the
handlers by simply setting the event to null.
Also, an event can handle its add/remove accessors however it wishes
to. You needn't necessarily have a separate field for each event, for
instance.
Suresh,
The way I understand it Events are to Delegate fields that Properties are to
other fields.
The event encapsulates & protects the underlying delegate value.
Chris Sells' book "Windows Forms Programming in C#" from Addison Wesley has
a chapter explaining the relationship. The story is also available on Code
Project:
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.