|
-
Nov 19th, 2004, 01:09 AM
#1
Button1 click oddity? [Resolved]
I have noticed that a button's click handler was assigned like this:
VB Code:
this.button1.Click += new System.EventHandler(this.button1_Click);
What's the deal with += here?
Last edited by mendhak; Nov 29th, 2004 at 03:28 AM.
-
Nov 19th, 2004, 03:57 AM
#2
Hyperactive Member
with the += you kind of subscribe to an event!
Keep Smiling - even if its hard 
Frankie Says Relax, wossname Says Yeah!
wossname:--Currently I'm wearing a gimp suit and a parachute.
C# - Base64 Blog
-
Nov 19th, 2004, 07:06 AM
#3
Hmm... subscribe. Sounds cool.
-
Nov 19th, 2004, 07:20 AM
#4
Yes, that's the equivelant to AddHandler in VB.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Nov 19th, 2004, 07:36 AM
#5
I see!
"Subscribe", though crptc in nature and not very understandable, sounds cool.
Thanks.
-
Nov 23rd, 2004, 08:03 AM
#6
I wonder how many charact
The event handlers already assigned to the click event, PLUS this new handler.
-
Nov 23rd, 2004, 02:13 PM
#7
Sleep mode
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 .
-
Nov 28th, 2004, 03:42 PM
#8
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.
I don't live here any more.
-
Nov 28th, 2004, 08:54 PM
#9
Frenzied Member
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.
-
Nov 29th, 2004, 03:30 AM
#10
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.
-
Nov 29th, 2004, 04:14 AM
#11
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.
I don't live here any more.
-
Nov 29th, 2004, 10:31 AM
#12
Frenzied Member
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
Code:
int i = -42;
i = + i;
System.Diagnostics.Debug.WriteLine(i.ToString());
prints out - 42.
-
Dec 4th, 2004, 03:24 AM
#13
yay gay
Re: Button1 click oddity? [Resolved]
 Originally Posted by wossname
"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?
\m/  \m/
-
Dec 4th, 2004, 03:57 AM
#14
Frenzied Member
Re: Button1 click oddity? [Resolved]
Getting off topic. += makes perfect sense for delegates, which I guess was part of the original author's question.
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
-
Dec 4th, 2004, 05:52 AM
#15
Re: Button1 click oddity? [Resolved]
VB 2005 will have everything that C# does. Correct?
-
Dec 4th, 2004, 01:55 PM
#16
Frenzied Member
Re: Button1 click oddity? [Resolved]
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.
-
Dec 6th, 2004, 03:48 AM
#17
Hyperactive Member
Re: Button1 click oddity? [Resolved]
 Originally Posted by mendhak
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.
Keep Smiling - even if its hard 
Frankie Says Relax, wossname Says Yeah!
wossname:--Currently I'm wearing a gimp suit and a parachute.
C# - Base64 Blog
-
Dec 7th, 2004, 04:48 AM
#18
Re: Button1 click oddity? [Resolved]
 Originally Posted by Sgt-Peppa
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.
-
Dec 7th, 2004, 05:32 AM
#19
Hyperactive Member
Re: Button1 click oddity? [Resolved]
 Originally Posted by mendhak
You mean the My keyword. I just read about that a couple days ago. Good stuff.
Yup, its called
MY
My bad , sorry
Stephan
Keep Smiling - even if its hard 
Frankie Says Relax, wossname Says Yeah!
wossname:--Currently I'm wearing a gimp suit and a parachute.
C# - Base64 Blog
-
Dec 8th, 2004, 02:36 AM
#20
Re: Button1 click oddity? [Resolved]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|