public delegate void MyDelegate(); MyDelegate del1 = new MyDelegate(MyMethod1); MyDelegate del2 = new MyDelegate(MyMethod2); bool result = del1.Equals(del2); // returns false
Action action1 = () => Console.WriteLine("Hello"); Action action2 = () => Console.WriteLine("Hello"); bool result = action1.Equals(action2); // returns trueIn this example, we use the built-in Action delegate type to create two delegate instances, "action1" and "action2". Both delegate instances reference the same method, which is to print the message "Hello" to the console. Therefore, the Equals method returns true. The System Delegate Equals method is part of the System namespace in C#, which is included in the .NET Framework Class Library.