events.

  • Thread starter Thread starter suresh
  • Start date Start date
S

suresh

is there any difference between events and multicast delegates.
if so how to differentiate.

thanx and regards.
 
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.

-vJ
 
thanx vijay.
but my question is please differentiate multicast delegates
from events.
thanx and regards.
 
Vijaye Raji said:
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:

http://www.thecodeproject.com/csharp/delegate_bedtime.asp

Hope this helps
Jay
 
Back
Top