C#字符串连接和字符串实习字符串

2023-09-05 03:07:52 作者:学长、你好衰

在执行中实习生池现有字符串的字符串连接,是一个新的字符串输入到实习生池,或者是引用返回到现有的字符串中的实习生池?根据这篇文章,String.Concat和StringBuilder的将插入新的字符串实例进实习生池?

When performing string concatentation of an existing string in the intern pool, is a new string entered into the intern pool or is a reference returned to the existing string in the intern pool? According to this article, String.Concat and StringBuilder will insert new string instances into the intern pool?

http://community.bartdesmet.net/博客/捷运/存档/ 2006/09/27 / 4472.aspx

任何人都可以解释如何串联工作的实习生池?

Can anyone explain how concatenation works with the intern pool?

推荐答案

如果您创建新的字符串,他们不会自动投入实习生池,除非您连接常量编译时,在这种情况下,编译器会创建一个字符串结果和实习生,作为JIT过程的一部分。

If you create new strings, they will not automatically be put into the intern pool, unless you concatenate constants compile-time, in which case the compiler will create one string result and intern that as part of the JIT process.