When I am concatenating object values together to form a string in VB.NET, is there a difference in performance or a recommended best practice between using the & concat or the + concat with calls to .ToString() on each object?
Example (which is faster or best practice):
Dim result1 As String = 10 & "em"
Dim result2 As String = 10.ToString() + "em"
There is no performance difference. If you omit the
.ToString()call explicitly the compiler will essentially just fill that in for you. If you use Option Explicit you will be required to call the method or you’ll get a compile error. I have heard good reasons for preferring both & and + semantically, so the choice there is really up to you.