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.
When concatenating three dynamic string values or less, use traditional string concatenation. When concatenating more than three dynamic string values, use StringBuilder . When building a big string from several string literals, use either the @ string literal or the inline + operator.
The ampersand symbol is the recommended concatenation operator. It is used to bind a number of string variables together, creating one string from two or more individual strings.
String concatenation is when you combine two or more strings into a single string variable. String concatenation is performed with the & symbol. Non-string values will be converted to string when using & . Always use & (ampersand) to perform string concatenation.
Microsoft's preference is for VB programmers to use &
for strings and not +
.
You can also use the + operator to concatenate strings. However, to eliminate ambiguity, you should use the & operator instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With