473,406 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

EventHandlers syntax

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
Nov 15 '05 #1
2 1103
> 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
Nov 15 '05 #2
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.


"Marc Scheuner [MVP ADSI]" <m.********@inova.SPAMBEGONE.ch> wrote in message
news:2t********************************@4ax.com...
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

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Catherine Lynn Smith | last post by:
I'm looking through the client side javascript reference and there's some mighty useful information in here, but it is not very specific on 'reading' information from event handlers. In the...
19
by: Nicolas Fleury | last post by:
Hi everyone, I would to know what do you think of this PEP. Any comment welcomed (even about English mistakes). PEP: XXX Title: Specialization Syntax Version: $Revision: 1.10 $...
3
by: Kiyomi | last post by:
Hello, I create a Table1 dynamically at run time, and at the same time, I would like to create LinkButton controls, also dynamically, and insert them into each line in my Table1. I would...
2
by: DKode | last post by:
Just curious, What is the proper way to add event handlers for web controls in a ascx/aspx page in csharp? The way I've been doing it up until this point is adding the += eventhandler in the...
3
by: Robert | last post by:
I need some assistance doing some "right way to do it" coding. The following are EventHandlers associated with Delegates in a child form that call a procedure in the MDI form that resets a timer....
1
by: Timo | last post by:
I haven't tried coding eventhandlers in Global.asax yet -- any "gotchas" I should be aware of? Do programming errors there require bouncing IIS? Will handlers in Global.asax be able to access...
3
by: Armin | last post by:
Hello I have a UserControl with a Click Event. Is it possible to find out the List of all Delegates/Eventhandlers using the Event. I read something about a "getinvocationlist" Methode for...
3
by: Manuel | last post by:
I'm trying to compile glut 3.7.6 (dowbloaded from official site)using devc++. So I've imported the glut32.dsp into devc++, included manually some headers, and start to compile. It return a very...
1
by: Kasper Birch Olsen | last post by:
Hi NG Im adding a bunch of linkbuttons to a page, in a for loop, but I cant get the eventhandlers to work. A simplyfied version of the code looks like this: for (int i = 0; i<10; i++) {...
8
by: Gina_Marano | last post by:
help, help, help. The microsoft documentation is getting me in a tizzy. What is the difference between the following: timer1.Tick += new System.EventHandler(timer1_Tick); &
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.