I have been told that multicast delegate in C# is immutable.But this code below seems to prove it is not.
Action a = () => { };
Action b = a;
Console.WriteLine(ReferenceEquals(a, b));
It will display True instead of False. Here is another example:
public delegate void MyHandler();
public class Klass
{
public event MyHandler onCreate;
public void Create()
{
MyHandler handler = onCreate;
if (handler != null)
{
handler();
}
Console.WriteLine(ReferenceEquals(handler, onCreate));
}
}
This class will be invoked as below:
Klass k = new Klass();
k.onCreate += () => { };
k.Create();
Same as above it will display True,so how could it be thread safe if the local copy is the same reference as the orignal one?