调用委托按引用相等进行比较:.Equals()
Action action1 = () => Console.WriteLine("Hello delegates"); Action action2 = () => Console.WriteLine("Hello delegates"); Action action1Again = action1; Console.WriteLine(action1.Equals(action1)) // 真正 Console.WriteLine(action1.Equals(action2)) // 假 Console.WriteLine(action1Again.Equals(action1)) // 真正
这些规则在进行多播委托时+=或-=在多播委托上也适用,例如,订阅和取消订阅事件时。