相关疑难解决方法(0)

.Net Framework中的字符串实习 - 有什么好处以及何时使用实习

我想知道特定于.Net框架的字符串实习的过程和内部.还想知道使用实习的好处以及我们应该使用字符串实习来提高性能的场景/情况.虽然我已经从Jeffery Richter的CLR书中学习实习,但我仍然感到困惑,并希望更详细地了解它.

[编辑]使用示例代码询问具体问题如下:

private void MethodA()
{
    string s = "String"; // line 1 - interned literal as explained in the answer        

    //s.intern(); // line 2 - what would happen in line 3 if we uncomment this line, will it make any difference?
}

private bool MethodB(string compareThis)
{
    if (compareThis == "String") // line 3 - will this line use interning (with and without uncommenting line 2 above)?
    {
        return true;
    }
    return false;
}
Run Code Online (Sandbox Code Playgroud)

.net c# string performance string-interning

40
推荐指数
5
解决办法
1万
查看次数

标签 统计

.net ×1

c# ×1

performance ×1

string ×1

string-interning ×1