M. Posseth said:
option strict on and use string.concat
this will never give unexpected behavior
... but it will lead to "unreadable" code.
and it will give you the advantage that you already know some syntaxt
when
switching to another .Net Language
Mhm... It's pretty easy to look up the string concatenation operator for
another programming language, isn't it?
& performs also a concat so there is no speed gain or benefit
except when you are using non string vars will concat probably be faster
as
the conversion is not necessary ( it is already enforced in dev time )
I recommend not to use 'String.Concat' when concatenating string literals.
Consider the following code:
\\\
MsgBox(String.Concat("Bla", "Foo"))
MsgBox("Bla" & "Foo")
///
Corresponding VB 7.1/.NET 1.1 IL:
\\\
IL_0001: ldstr "Bla"
IL_0006: ldstr "Foo"
IL_000b: call string [mscorlib]System.String::Concat(string,
string)
IL_0010: ldc.i4.0
IL_0011: ldnull
IL_0012: call valuetype
[Microsoft.VisualBasic]Microsoft.VisualBasic.MsgBoxResult
[Microsoft.VisualBasic]Microsoft.VisualBasic.Interaction::MsgBox(object,
valuetype [Microsoft.VisualBasic]Microsoft.VisualBasic.MsgBoxStyle,
object)
IL_0017: pop
IL_0018: ldstr "BlaFoo"
IL_001d: ldc.i4.0
IL_001e: ldnull
IL_001f: call valuetype
[Microsoft.VisualBasic]Microsoft.VisualBasic.MsgBoxResult
[Microsoft.VisualBasic]Microsoft.VisualBasic.Interaction::MsgBox(object,
///
As you can see, the compiler will perform the string concatenation done
using the '&' operator at compile-time, if possible, whereas this isn't
the case for 'String.Concat'.