I\'m under the impression that these two commands result in the same end, namely incrementing X by 1 but that the latter is probably more efficient.
If this is not c
They may be the same in VB; they are not necessarily the same in C (where the operator comes from).
they compile to the same, the second is just easier to type.
The answers specifying evaluation are certainly correct in terms of what a +=
do, in general languages. But in VB.NET, I assume X
specified in the OP is a variable or a property.
They'll probably compile to the same IL.
VB.NET is a specification of a programming language. Any compiler that conforms to what's defined in the spec can be a VB.NET implementation. If you edit the source code of the MS VB.NET compiler to generate crappy code for X += 1
case, you'll still conform to VB.NET spec (because it didn't say anything about how it's going to work. It just says the effect will be exactly the same, which makes it logical to generate the same code, indeed).
While the compiler is very very likely (and I feel it really does) generate the same code for both, but it's pretty complex piece of software. Heck, you can't even guarantee that a compiler generates the exact same code when the same code is compiled twice!
What you can feel 100% secure to say (unless you know the source code of the compiler intimately) is that a good compiler should generate the same code, performance-wise, which might or might not be the exact same code.
The optimizer probably produces the same result, if x is a simple type like int or float.
If you'd use some other language (limited VB knowledge here, can you overload +=?) where x could be one big honking object, the former creates and extra copy, which can be hundreds of megs. The latter does not.