EventHandlers syntax

  • Thread starter Thread starter news.microsoft.com
  • Start date Start date
N

news.microsoft.com

Hi,

Why was it decided to implement subscribing an observer to an event with
+= and -= operators and not providing some kind of .Add and .Remove methods?
Wouldnt this be nicer?

having it as something.EventHere += new BlahHandler(class.method):

instead of

something.EventHere.Add(class.method); for +=

and

something.EventHere.Remove(class.Method)

what other way are we going to add a callback method?

= ? then why not use singlecast delegates. we could always provide a
..clear() method

Just a thought
 
Why was it decided to implement subscribing an observer to an event with
+= and -= operators and not providing some kind of .Add and .Remove methods?
Wouldnt this be nicer?

having it as something.EventHere += new BlahHandler(class.method):

instead of
something.EventHere.Add(class.method); for +=

Well, I guess this really boils down to a personal preference - one
could argue MS should have provided both ways, especially seeing that
in VB.NET, you do have the AddHandler method.

But really, in the end, functionally you're not getting any additional
power by having an Add method - so just get used to the way it is now
and get on to more important problems ;-)

Marc
================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 
Well i mean its just a COLLECTION (List) of delegates to invoke (for a
Multicast delegate) and collection classes have Add and Remove methods so
why not provide the same for the delegate invokation collection? They do
have .Combine methods, just a thought.

I havnt tried it but if we call += on a SingleCast delegate do we get an
error? Depends how one views the += operator, is it changed to a = or is it
treated as an error? Would the compiler be that strict? Havnt tried it yet
just a curiosity.
 
Back
Top