In VB.NET, is there any advantage to using & to concatenate strings instead of +?
For example
Dim x as String = "hello" + " there"
vs.
Dim x as String = "hello" & " there"
Yes, I know for a lot of string concatenations I’d want to use StringBuilder, but this is more of a general question.
I’ve heard good, strong arguments in favor of both operators. Which argument wins the day depends largely on your situation. The one thing I can say is that you should standardize on one or the other. Code that mixes the two is asking for confusion later.
The two arguments I remember right now for favoring
&:Option Strictand have two numeric strings, it’s easy for the compiler to confuse your meaning of of the+operator with, you know, arithmetic additionAnd for
+:&is almost unique to VB, while+between strings is understood in many languages to mean concatenation, so you gain a little something in readability.