Essential C# Delegates  Suggest an edit

Delegate Equality

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.


Table Of Contents
22 Enum
25 GUID
95 Delegates
107 Stream
108 Timers
  ↑ ↓ to navigate     ↵ to select     Esc to close