Is this a bug with events and add/remove?

  • Thread starter Thread starter David Levine
  • Start date Start date
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.
I 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.
Quite so. That is a side-effect of the implementation; it as if the
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top