<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>

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

        Why only literal strings saved in the intern pool by default?(为什么默认情况下只保存在实习生池中的文字字符串?)

          <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

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

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Populate ListBox with a IEnumrable on another thread (winforms)(在另一个线程(winforms)上使用 IEnumrable 填充 ListBox)
                  listbox selected item give me quot; System.Data.DataRowViewquot; , C# winforms(列表框选择的项目给我quot;System.Data.DataRowView, C# Winforms)
                  Cannot remove items from ListBox(无法从列表框中删除项目)
                  Preventing ListBox scrolling to top when updated(更新时防止列表框滚动到顶部)
                  Drag and drop from list to canvas on windows phone with MVVM(使用 MVVM 在 Windows 手机上从列表拖放到画布)
                  Deselection on a WPF listbox with extended selection mode(具有扩展选择模式的 WPF 列表框上的取消选择)

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

                          • <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>
                              <tbody id='TBWl9'></tbody>
                          • <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>