I've just noticed something rather odd and disturbing. The following
code displays "True":
using System;
class Test
{
public static void Main(string[] args)
{
string x = new string ("".ToCharArray ());
string y = new string ("".ToCharArray ());
Console.WriteLi ne (object.Referen ceEquals (x, y));
}
}
In other words, new string(...) is *not* returning a new string
reference.
This worries me - not so much for the specific example, but for the
precedent set. What other new ... expressions might return non-new
references? This could have significant implications in multi-
threading, where you may rely on two references being different for
locking purposes.
--
Jon Skeet - <skeet@pobox.co m>
If replying to the group, please do not mail me too
code displays "True":
using System;
class Test
{
public static void Main(string[] args)
{
string x = new string ("".ToCharArray ());
string y = new string ("".ToCharArray ());
Console.WriteLi ne (object.Referen ceEquals (x, y));
}
}
In other words, new string(...) is *not* returning a new string
reference.
This worries me - not so much for the specific example, but for the
precedent set. What other new ... expressions might return non-new
references? This could have significant implications in multi-
threading, where you may rely on two references being different for
locking purposes.
--
Jon Skeet - <skeet@pobox.co m>
If replying to the group, please do not mail me too
Comment