Delegate Equality

suggest change

Calling .Equals() on a delegate compares by reference equality:

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

These rules also apply when doing += or -= on a multicast delegate, for example when subscribing and unsubscribing from events.

Feedback about page:

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


Delegates:
* Delegate Equality

Table Of Contents
17 Regex
19 Arrays
21 Enum
22 Tuples
24 GUID
27 Looping
36 Casting
46 Methods
88 Events
92 Structs
94 Delegates
104 Indexer
106 Stream
107 Timers
109 Threading
127 Caching
135 Pointers
147 C# Script