
Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
> And it's right. An event is really just an add/remove pair of methods.
> (There's also raise, but that doesn't get exposed in C#.) When you
No, there is no such thing as "raise"!
Events are stored as multicast delegates and used as such.
> declare a field-like event, that's really declaring both the event
> *and* a delegate. When you access the name within the class, it refers
> to the delegate. When you access the name outside the class, it refers
> to the event. Delegates can be invoked - events can't.
Well events are just delegate, and of course they could be ".Invoke(..)", as
any other delegate.
But a semantic akin to private/protect/public prevent to do it from anywhere
but the declaring class itself.
Jon Skeet [C# MVP] - 20 Jul 2006 08:03 GMT
> > And it's right. An event is really just an add/remove pair of methods.
> > (There's also raise, but that doesn't get exposed in C#.) When you
>
> No, there is no such thing as "raise"!
> Events are stored as multicast delegates and used as such.
C# doesn't expose it, but it's part of the .NET event system.
See CLI spec partition 1 section 10.4.
> > declare a field-like event, that's really declaring both the event
> > *and* a delegate. When you access the name within the class, it refers
[quoted text clipped - 3 lines]
> Well events are just delegate, and of course they could be ".Invoke(..)", as
> any other delegate.
No, events aren't delegates any more than properties are variables. An
event is solely a set of appropriately decorated methods. It's possible
(although it would be very odd) to implement an event without actually
storing a delegate. You'd need to store pretty much the same
information, but the only ways in which events are intrinsically linked
to delegates are:
1) C#'s field-like event support, which declares a delegate variable
and an event
2) the signatures of event methods.
> But a semantic akin to private/protect/public prevent to do it from anywhere
> but the declaring class itself.
Events only have add/remove semantics, along with the raise as
mentioned before. Whether they are implemented by having a delegate
variable is an implementation matter. Some implementations keep the
delegates for all events in a hashtable, so that you don't need a
variable per event where there are lots of events which may not be
subscribed to at all.
Jon