String.intern method

xiaoxiao2021-03-06  101

The following paragraph String s = "Hello"; string s1 = "hello"; console.writeline (Object.ReferenceEquals (s, s, s1)); what is the result of the output? Look, S is a string, S2 is another string, obviously not an object, and it should output FALSE

However, the facts of the facts are True. If S1 here, S1 is other type Object here, but the string is another matter

The public language runtime is stored in a string by maintaining a table, which is called a detention pool, which contains a reference to each unique string in programming or created in programming. Therefore, an example of a string having a particular value is only one in the system.

For example, if the same string is assigned to several variables, the run library retrieves the same reference to the string from the detention pool, and assigns it to each variable.

Thus, when the CLR is initialized, only one "hello" is saved in the detainement pool, and the pointer is to one "Hello" when the S1 and S2 initialize.

The reason why it is doing, nothing more than performance considerations, specific to ".NET framework program design (revisions)" 12.2.4, probably on page 262

转载请注明原文地址:https://www.9cbs.com/read-104175.html

New Post(0)