与this问题类似,但对于VB.NET,因为我了解到这是语言问题。
例如,编译器是否会知道翻译
Dim s As String = "test " + "this " + "function"
至
Dim s As String = "test this function"
从而避免使用字符串连接对性能造成影响?
最佳答案
是的。是的。我只测试了VS 2008,但我强烈怀疑以前的版本也是如此。
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. -注意字符串“测试此功能”
{
.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
}
关于.net - VB.NET是否优化字符串文字的串联?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/290527/