Use operator shortcuts in VB.NET

Java and C++ developers have long been accustomed to using operator shortcuts for evaluating an expression and then stuffing the results of that expression back into one of the original variables. To do this kind of thing in VB6, you had to use code like this:

strVar1 = "Testing "
strVar2 = "One, Two, Three"
strVar1 = strVar1 & strVar2
'strVar1 is now equal to "Testing One, Two, Three"

Many developers are continuing to use this syntax in VB.NET. But VB.NET now also supports the same operator shortcuts the Java and C++ guys have always had. So instead, you can now say:

strVar1 = "Testing "
strVar2 = "One, Two, Three"
strVar1 &= strVar2
'strVar1 is now equal to "Testing One, Two, Three"

You can likewise use +=, -=, *=, /=, \=, and ^=. Try it -- we think you'll like it!

No comments:

Post a Comment