Similar to this question, but for VB.NET since I learned this is a language thing.
For instance, would the compiler know to translate
Dim s As String = "test " + "this " + "function"
to
Dim s As String = "test this function"
and thus avoid the performance hit with the string concatenation?
Each time strcat calls, the loop will run from start to finish; the longer the string, the longer the loop runs. Until the string is extensive, the string addition takes place very heavy and slow.
Concatenation operators join multiple strings into a single string. There are two concatenation operators, + and & . Both carry out the basic concatenation operation, as the following example shows.
Note that regular string concatenations are faster than using the StringBuilder but only when you're using a few of them at a time. If you are using two or three string concatenations, use a string.
String OperatorThe "&" operator joins two strings together. Example: Dim String1 As String = "123" Dim String2 As String = "456" Dim String3 As String String3 = String1 & String2 ' Results in "123456". The "+" operator may be used in place of "&".
Yes. It Does. I only tested VS 2008 but I strongly suspect previous versions did as well.
VB.NET
Public Class Class1
Dim s As String = "test " + "this " + "function"
Public Function test() As String
Return s
End Function
End Class
I.L. - Notice the string "test this function"
{
.maxstack 8
L_0000: ldarg.0
L_0001: call instance void [mscorlib]System.Object::.ctor()
L_0006: nop
L_0007: ldarg.0
L_0008: ldstr "test this function"
L_000d: stfld string ClassLibrary1.Class1::s
L_0012: nop
L_0013: ret
}
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