<tfoot id='BfV7w'></tfoot>

    <small id='BfV7w'></small><noframes id='BfV7w'>

  • <legend id='BfV7w'><style id='BfV7w'><dir id='BfV7w'><q id='BfV7w'></q></dir></style></legend>

      <bdo id='BfV7w'></bdo><ul id='BfV7w'></ul>
        <i id='BfV7w'><tr id='BfV7w'><dt id='BfV7w'><q id='BfV7w'><span id='BfV7w'><b id='BfV7w'><form id='BfV7w'><ins id='BfV7w'></ins><ul id='BfV7w'></ul><sub id='BfV7w'></sub></form><legend id='BfV7w'></legend><bdo id='BfV7w'><pre id='BfV7w'><center id='BfV7w'></center></pre></bdo></b><th id='BfV7w'></th></span></q></dt></tr></i><div id='BfV7w'><tfoot id='BfV7w'></tfoot><dl id='BfV7w'><fieldset id='BfV7w'></fieldset></dl></div>

        为什么默认情况下只保存在实习生池中的文字字符串?

        时间:2023-10-06

          <tbody id='3HGPo'></tbody>

        <small id='3HGPo'></small><noframes id='3HGPo'>

      1. <legend id='3HGPo'><style id='3HGPo'><dir id='3HGPo'><q id='3HGPo'></q></dir></style></legend>

          <tfoot id='3HGPo'></tfoot>
              • <i id='3HGPo'><tr id='3HGPo'><dt id='3HGPo'><q id='3HGPo'><span id='3HGPo'><b id='3HGPo'><form id='3HGPo'><ins id='3HGPo'></ins><ul id='3HGPo'></ul><sub id='3HGPo'></sub></form><legend id='3HGPo'></legend><bdo id='3HGPo'><pre id='3HGPo'><center id='3HGPo'></center></pre></bdo></b><th id='3HGPo'></th></span></q></dt></tr></i><div id='3HGPo'><tfoot id='3HGPo'></tfoot><dl id='3HGPo'><fieldset id='3HGPo'></fieldset></dl></div>

                  <bdo id='3HGPo'></bdo><ul id='3HGPo'></ul>

                  本文介绍了为什么默认情况下只保存在实习生池中的文字字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  为什么默认情况下只有文字字符串保存在实习池中?

                  Why by default only literal strings are saved in the intern pool?

                  示例来自 MSDN:

                  String s1 = "MyTest";
                  String s2 = new StringBuilder().Append("My").Append("Test").ToString(); 
                  String s3 = String.Intern(s2); 
                  Console.WriteLine("s1 == '{0}'", s1);
                  Console.WriteLine("s2 == '{0}'", s2);
                  Console.WriteLine("s3 == '{0}'", s3);
                  Console.WriteLine("Is s2 the same reference as s1?: {0}", (Object)s2==(Object)s1); 
                  Console.WriteLine("Is s3 the same reference as s1?: {0}", (Object)s3==(Object)s1);
                  
                  /*
                  This example produces the following results:
                  s1 == 'MyTest'
                  s2 == 'MyTest'
                  s3 == 'MyTest'
                  Is s2 the same reference as s1?: False
                  Is s3 the same reference as s1?: True
                  */
                  

                  推荐答案

                  简短的回答:实习文字字符串在运行时很便宜并且节省内存.嵌入非文字字符串在运行时很昂贵,因此节省了少量内存,以换取使常见情况变慢.

                  The short answer: interning literal strings is cheap at runtime and saves memory. Interning non-literal strings is expensive at runtime and therefore saves a tiny amount of memory in exchange for making the common cases much slower.

                  interning-strings-at-runtime优化"的成本并没有带来收益,因此实际上并不是优化.实习文字字符串的成本很便宜,因此确实为收益付出了代价.

                  The cost of the interning-strings-at-runtime "optimization" does not pay for the benefit, and is therefore not actually an optimization. The cost of interning literal strings is cheap and therefore does pay for the benefit.

                  我在这里更详细地回答你的问题:

                  I answer your question in more detail here:

                  http://blogs.msdn.com/b/ericlippert/archive/2009/09/28/string-interning-and-string-empty.aspx

                  这篇关于为什么默认情况下只保存在实习生池中的文字字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:JIT 编译器如何编译泛型? 下一篇:为什么 C# 不允许我在不同的范围内使用相同的变量名?

                  相关文章

                        <bdo id='TBWl9'></bdo><ul id='TBWl9'></ul>

                    1. <small id='TBWl9'></small><noframes id='TBWl9'>

                      <legend id='TBWl9'><style id='TBWl9'><dir id='TBWl9'><q id='TBWl9'></q></dir></style></legend>
                      <tfoot id='TBWl9'></tfoot>
                    2. <i id='TBWl9'><tr id='TBWl9'><dt id='TBWl9'><q id='TBWl9'><span id='TBWl9'><b id='TBWl9'><form id='TBWl9'><ins id='TBWl9'></ins><ul id='TBWl9'></ul><sub id='TBWl9'></sub></form><legend id='TBWl9'></legend><bdo id='TBWl9'><pre id='TBWl9'><center id='TBWl9'></center></pre></bdo></b><th id='TBWl9'></th></span></q></dt></tr></i><div id='TBWl9'><tfoot id='TBWl9'></tfoot><dl id='TBWl9'><fieldset id='TBWl9'></fieldset></dl></div>