3 ms·
I would say that it is because each time ToString() is called a new string is created, and at least in the Java I believe that is what will happen, comparison w
by LoneWolf 14y ago
I would say that it is because each time ToString() is called a new string is created, and at least in the Java I believe that is what will happen, comparison will be false because they are not the same instance.
- ufmace 14y agoIt's a bit trickier than that due to string interning. That's where there is only one instance framework-wide of a string of a particular value. Try to create a second string with the same value as one you have created already, and you get back a reference to the first string instance. As an example: (object)"XYZ" == (object)"XYZ" returns true. So does: (object) String.Intern(x.ToString()) == (object) String.Intern(x.ToString()) The trick is to know exactly which strings are interned, and when. I initially thought that all strings were, but it seems that string literals in code are always interned, and dynamically-created strings are mostly not interned automatically, but can be manually. http://en.wikipedia.org/wiki/String_interning http://en.wikipedia.org/wiki/String_interning http://msdn.microsoft.com/en-us/library/system.string.intern.aspx http://msdn.microsoft.com/en-us/library/system.string.intern...