简体   繁体   中英

C# string concatenation and string interning

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/blogs/bart/archive/2006/09/27/4472.aspx

Can anyone explain how concatenation works with the intern pool?

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

You can see whether a string has been interned by calling String.IsInterned . The call will return a new string that is either a reference to an interned string equal to the string that was passed as an argument, or null if the string was not interned.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM