c# - string concatenation and reference equality -
in c# strings immutable , managed. in theory mean concatenation of strings a , b cause allocation of new buffer pretty obfuscated. when concatenate identity (the empty string) reference maintains intact. compile time optimization or overloaded assignment operator making decision not realloc @ runtime? furthermore, how runtime/compiler handle s2 's value/allocation when modify value of s1 ? program indicate memory @ original address of s1 remains intact (and s2 continues pointing there) while relloc occurs new value , s1 pointed there, accurate description of happens under covers? example program; static void main(string[] args) { string s1 = "some random text chose"; string s2 = s1; string s3 = s2; console.writeline(object.referenceequals(s1, s2)); // true s1 = s1 + ""; console.writeline(object.referenceequals(s1, s2)); // true console.writeline(s2); s1 = s1 + " else...