Delegate Equality

suggest change

Equals 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

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents