On 2/20/08, Ryan Heath <[EMAIL PROTECTED]> wrote:
> In your example, anyone can fire the FooChanged.
>  When declared as an event, only instances of Foo can fire it, while
>  registering is still supported through += and -=.
>
>  // Ryan

Not only that but users of the class could also directly assign the
delegate field:

x.FooChanged = new EventHandler(blah);

which will replace all previous registered handlers with the new one.

In short,

public EventHandler FooChanged;

is a field named FooChanged of type EventHandler and

public event EventHandler FooChanged;

encapsulates that field and protects its access (external code cannot
raise the event and cannot change the value of the field. More or less
like a property.

Sébastien

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to