C # string concatenation and string interning

When performing string concatenation of an existing string in the first pool, is the new string entered in the internal pool, or is the link returned to the existing string in the pool? According to this article, String.Concat and StringBuilder insert new string instances into the main pool?

http://community.bartdesmet.net/blogs/bart/archive/2006/09/27/4472.aspx

Can someone explain how concatenation works with the internal pool?

+4
source share
2 answers

If you create new lines, they will not be automatically placed in the internal pool unless you combine the compilation time of the constants, in which case the compiler will create one line result and an intern that will be part of the JIT process.

+4
source

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

0
source

Source: https://habr.com/ru/post/1276505/


All Articles