Delegate Equality
suggest changeEquals on a delegate compares invocation lists: the same methods on the same targets. Two lambdas with the same source are still different methods, so they are not equal. += and -= use that comparison when adding or removing a handler:
Action action1 = () => Console.WriteLine("Hello delegates");
Action action2 = () => Console.WriteLine("Hello delegates");
Action action1Again = action1;
Console.WriteLine(action1.Equals(action1)); // True
Console.WriteLine(action1.Equals(action2)); // False
Console.WriteLine(action1Again.Equals(action1)); // True
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents