代表相等
在委托上调用 .Equals()
比较引用相等:
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
在多播委托上执行+=
或 -=
时,这些规则也适用,例如订阅和取消订阅事件时。