D
David Levine
Barry Kelly said:I think this is slightly unfortunate, but the desire behind it is
reasonable - it makes the common-place job of adding event declarations
to classes less onerous.
The desire is legitimate; the implementation was unfortunate. Code that
worked when the event was declared as a field will break when the add/remove
accessors are added.
Quite so. That is a side-effect of the implementation; it as if theI wish to make clear for everybody (as you already know) that the empty
list for a delegate is in fact a null reference. Delegates are
effectively nodes in a single-linked list - so there can be no "empty
list". This implementation approach also reduces the number of objects
for unsubscribed events.
implementation forced the language to surface the feature in this manner
rather then it being designed to work this way. I believe they should have
decided how events should have been exposed and then chosen an
implementation that supported that requirement. There are undoubtedly a
large number of apps out there that simply invoke the event (delegate)
without checking it for null because when they tested it there was always a
subscriber - it always worked, but it's a failure waiting to happen.