PDA

Click to See Complete Forum and Search --> : Button1 click oddity? [Resolved]


mendhak
Nov 19th, 2004, 12:09 AM
I have noticed that a button's click handler was assigned like this:


this.button1.Click += new System.EventHandler(this.button1_Click);


What's the deal with += here?

Sgt-Peppa
Nov 19th, 2004, 02:57 AM
with the += you kind of subscribe to an event!

mendhak
Nov 19th, 2004, 06:06 AM
Hmm... subscribe. Sounds cool. :D

crptcblade
Nov 19th, 2004, 06:20 AM
Yes, that's the equivelant to AddHandler in VB.

mendhak
Nov 19th, 2004, 06:36 AM
I see!

"Subscribe", though crptc in nature and not very understandable, sounds cool.

Thanks.

nemaroller
Nov 23rd, 2004, 07:03 AM
The event handlers already assigned to the click event, PLUS this new handler.

Pirate
Nov 23rd, 2004, 01:13 PM
Try the nice feature in C# :
Add this :

this.button1.Click + , then + , then tab . It creates the event handler automatically .

mendhak , it'd be cooler if you check that green mark . It'd looks nice .:afrog:

wossname
Nov 28th, 2004, 02:42 PM
Originally posted by mendhak
I see!

"Subscribe", though crptc in nature and not very understandable, sounds cool.

Thanks.

"Ascribe" is probably a better word.

In my opinion, the only advantage C# has over VB.net is the ability to override operators. That is what they have done here, they have perverted the self-assignment operator += so that it adds an error handler to an already existing list of error handlers. It is not the conventional usage of the += op.

Note: VB can also assign multiple (consecutive) event handlers to an event.

Mike Hildner
Nov 28th, 2004, 07:54 PM
I guess that depends on how you think about it. What is confusing, at least to me, is when operators do very different things. You have to read the context of how it's used to understand what's going on.

For example, in C#, the "+" operator does one of three things, depending on the context. And I just mean the binary operator, use of the unary + never made sense to me.

For numerics, it calculates the sum, for strings, it concatenates the two strings, and for delegate types, it does delegate concatenation.

I guess it's easy enough to get used to, but I would prefer one operand to add numbers, another to concatenate strings, and another for delegate types.

But that's just me.

mendhak
Nov 29th, 2004, 02:30 AM
Originally posted by wossname
In my opinion, the only advantage C# has over VB.net is the ability to override operators. That is what they have done here, they have perverted the self-assignment operator += so that it adds an error handler to an already existing list of error handlers. It is not the conventional usage of the += op.


My quest of learning VB had made me overlook that part.

One peeve of mine is that C# gets the /// summary and VB.NET doesn't. Imagine the multitude of Sandpaper.NET users out there who need to constantly refer to the documentation. :D

wossname
Nov 29th, 2004, 03:14 AM
Originally posted by Mike Hildner
the unary + never made sense to me.

I've seen it used as a shortcut for Math.Abs(). Forces any value to positive.

Bad code practice if you ask me though.

Mend, I agree about the ///<summary> thingy. What I am planning to do though, is use the "Build Comment Pages" utility in the IDE. The output isn't very stylish but it takes a huge amount of the donkeywork out of writing the documentation.

Mike Hildner
Nov 29th, 2004, 09:31 AM
I've seen it used as a shortcut for Math.Abs(). Forces any value to positive. I didn't know that. Gave it a try, but I guess I'm doing something wrong? This code int i = -42;
i = + i;
System.Diagnostics.Debug.WriteLine(i.ToString());
prints out - 42.

PT Exorcist
Dec 4th, 2004, 02:24 AM
"Ascribe" is probably a better word.

In my opinion, the only advantage C# has over VB.net is the ability to override operators. That is what they have done here, they have perverted the self-assignment operator += so that it adds an error handler to an already existing list of error handlers. It is not the conventional usage of the += op.

Note: VB can also assign multiple (consecutive) event handlers to an event.
and pointers?

Mike Hildner
Dec 4th, 2004, 02:57 AM
Getting off topic. += makes perfect sense for delegates, which I guess was part of the original author's question.
and pointers? Without getting into a language war, I agree. Please correct me if I'm wrong, but I believe that C# can do everything that VB.NET can do, plus some. VB.NET cannot claim the same thing. There's nothing unique to VB.NET that can't be done in C#.

Coming from a classic VB background, naturaly I started with VB.NET. From there, it's easy to get exposed to C#, which now I prefer, for the above stated reasoning.

That, and the emotional security that comes with a semicolon at the end of every line :)

mendhak
Dec 4th, 2004, 04:52 AM
VB 2005 will have everything that C# does. Correct?

Mike Hildner
Dec 4th, 2004, 12:55 PM
mendhak, not sure if you were directing that question at me or not. Answering just in case. I have no idea what tomorrow may bring. Seems like you hear things that VB will "catch up" to some features that C# has, I can only hope that C# IntelliSense gets as good as VB.

Sgt-Peppa
Dec 6th, 2004, 02:48 AM
VB 2005 will have everything that C# does. Correct?
Actually VB 2005 will have some features that C# doesnt. For example the Me class. This includes some features such as checking network connection, getting the name of the current machine,..... that got more complicated from vb6 to vb .net. They bring back that easy access to key features like that in vb.net 2005.

mendhak
Dec 7th, 2004, 03:48 AM
Actually VB 2005 will have some features that C# doesnt. For example the Me class. This includes some features such as checking network connection, getting the name of the current machine,..... that got more complicated from vb6 to vb .net. They bring back that easy access to key features like that in vb.net 2005.


You mean the My keyword. I just read about that a couple days ago. Good stuff.

Sgt-Peppa
Dec 7th, 2004, 04:32 AM
You mean the My keyword. I just read about that a couple days ago. Good stuff.

Yup, its called
MY

My bad :blush:, sorry

Stephan

mendhak
Dec 8th, 2004, 01:36 AM
My.bad :blush:


:lol: :lol: :afrog: