将 委托对象名=null
就是将委托直接值为null
建议楼主自习看一下委托是怎么实现的,好久之前研究过,记得是两个方法都会存储在一个称为调用列表的结构中,按照类似于队列的顺序被连续调用。所以会调用两次。记得有remove方法或者啥的,能移除一个委托。可以参考一下<visual studio 2008核心编程>静下心来,仔细看一下。收获蛮大的。祝你好运
而且最重要的一点,委托在编译后是一个类!!!
参考:
1 public delegate void OperatorChangeEventHandler(); 2 3 4 private event OperatorChangeEventHandler mOperatorMgrChangeEvent; 5 public event OperatorChangeEventHandler OperatorMgrChangeEvent 6 { 7 add 8 { 9 if (mOperatorMgrChangeEvent != null) 10 { 11 Delegate[] Delegates = mOperatorMgrChangeEvent.GetInvocationList(); 12 for (int i = 0; i < Delegates.Length; i++) 13 { 14 mOperatorMgrChangeEvent = Delegate.Remove(mOperatorMgrChangeEvent, Delegates[i]) as OperatorChangeEventHandler; 15 } 16 mOperatorMgrChangeEvent = Delegate.Combine(mOperatorMgrChangeEvent, value) as OperatorChangeEventHandler; 17 } 18 else 19 { 20 mOperatorMgrChangeEvent += value; 21 } 22 } 23 remove 24 { 25 if (mOperatorMgrChangeEvent == null) 26 return; 27 else 28 mOperatorMgrChangeEvent -= value; 29 } 30 }