And another version in other words:
MyDelegate delegateOriginal = Method1; MyDelegate copyOfOriginal = delegateOriginal; Object.ReferenceEquals(printAllhandler, anotherHandler); // return true
Returns true because the delegateOriginal and copyOfOriginal refer to the same instance.
Then
delegateOriginal += Method2;
If the delegate was changed with the following expression, then true will be returned, since the variables will refer to the same object, but:
Object.ReferenceEquals(printAllhandler, anotherHandler); // return false
Because delegate is immutable.
String delegateOriginal += Method2; will create a new instance of the delegate and place a link to the source variable.
source share