k==s // true // 2> Object.Re...">

Intering string in C #

Consider the following code snippet in C #

string s = "hi"; object k="hi".Substring(0); // 1> k==s // true // 2> Object.ReferenceEquals(s,k) //true 

but when

 Object k="hii".Substring(0,2); // 1> k==s // false // 2> Object.ReferenceEquals(s,k) //false 

I find it difficult to understand why in the first case the lines were interned, and in the second case this is not so. It would also be very helpful if anyone can specify the rules when string interning happens in C #.

+5
source share

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


All Articles