I read that delegate are immutable objects.
If I have into a thread:
EventHandler handler = (s, e) => Console.WriteLine("...");
EventHandler copy = handler;
copy(new object(), EventArgs.Empty);
that copy is a thread safety operations so when I invoke copy(...)
if another thread eliminated the delegate from handler
no exception can raise.
However If I make, i.e,:
handler.GetHashCode()
and copy.GetHashCode()
they both returns the same code.
I thought that the assignment operator did a new instance of that delegate
and that the new reference had put into copy
variable...
How can, thus, copy
and handler
be independent if they both references
the same object in memory?
Confused!