请问VB.NET优化字符串的串联? [英] Does VB.NET optimize the concatenation of string literals?

查看:95
本文介绍了请问VB.NET优化字符串的串联?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类似于<一href="http://stackoverflow.com/questions/288794/does-c-optimize-the-concatenation-of-string-literals">this的问题,但对于VB.NET,因为我了解到这是一个语言的事情。

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"

Dim s As String = "test this function"

,从而避免与字符串连接的性能影响?

and thus avoid the performance hit with the string concatenation?

推荐答案

是的。它的作用。我只测试VS 2008,但我强烈怀疑previous版本中那样为好。

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。 - 请注意,字符串测试这个功能

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 
}

这篇关于请问VB.NET优化字符串的串联?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆