Underlying references of named method delegates

suggest change

When assigning named methods to delegates, they will refer to the same underlying object if:

public class Greeter
   public void WriteInstance()

   public static void WriteStatic()

// ...

Greeter greeter1 = new Greeter();
Greeter greeter2 = new Greeter();

Action instance1 = greeter1.WriteInstance;
Action instance2 = greeter2.WriteInstance;
Action instance1Again = greeter1.WriteInstance;

Console.WriteLine(instance1.Equals(instance2)); // False
Console.WriteLine(instance1.Equals(instance1Again)); // True

Action @static = Greeter.WriteStatic;
Action staticAgain = Greeter.WriteStatic;

Console.WriteLine(@static.Equals(staticAgain)); // True

Feedback about page:

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

Table Of Contents