Why events, why not just delegates?

  • Thread starter Thread starter Marty McDonald
  • Start date Start date
M

Marty McDonald

It is still unclear to me why we would use events when delegates seem to do
just fine. People say that events make it so the publisher doesn't need to
know about the listeners. What does that mean? Why are events better than
delegates? Thanks
 
Marty,
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
 
Hi Marty,

Jay's link is very good.
You may also take a look at the links below.

Events Tutorial
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/
vcwlkEventsTutorial.asp
Delegates Tutorial
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/
vcwlkdelegatestutorial.asp

Raising Events and Responding to Events
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/ht
ml/raiserespeven.asp
Events and Delegates
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconeventsdelegates.asp

If you have any related question, please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
 
Hi Marty,

If you still have questions on this issue, please reply the thread to let
us know you need further assistance.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top