Alex Rivera | Logout

The difference between + and & for joining strings in VB.NET

Asked 2009-04-09T14:56:42.537
73

What is the difference between + and & for joining strings in VB.NET?

Edit
Report

2 Answers

3

The + operator can be either addition or concatenation. The & is only concatenation. If the expressions are both strings the results would be the same.

I use & when working with strings, and + when working with numbers, so there is never confusion about my intent. If you mistakenly use + and one expression is a string and one is a number, you run the risk of un-desired results.

answered 2009-04-09T15:03:41.633
0

None when joining strings:

    Dim string1 As String = "A" + "B"
    Dim string2 As String = "A" & "B"

    If string1.Equals(string2) And string2.Equals(string1) Then
        Debugger.Break()
    End If
answered 2009-04-09T15:00:06.493

Your Answer