委托用法
                            
                            
                            一、委托callback 回調(diào)函數(shù)聲明委托:(與聲明類相似)public delegate string MyDelegate(string sInput);使用委托:1.?MyDelegate myDelegateCase = new MyDelegate(InvokeMethod);private string InvokeMethod(string sInput){return sInput);}2. 委托推斷MyDelegate myDelegateCase = InvokeMethod;3. 匿名方法MyDelegate myDelegateCase = delegate(string sInput){ return sInput; };多播委托MyDelegate myDelegateCase = InvokeMethod1;myDelegateCase += InvokeMethod2;委托總是帶有1個參數(shù)的構(gòu)造函數(shù),這個參數(shù)就是委托引用的方法。二、事件EventHandler 1 總是返回void,2 參數(shù)必須是object、EventArg聲明委托和事件:public delegate void ActionEventHandler(object sender, ActionCancelEventArgs ev);public static event ActionEventHandler Action;定義引發(fā)事件:protected void OnAction(object sender, ActionCancelEventArgs ev){if (Action != null){Action(sender, ev);}}Class.Action += new ActionEventHandler(MainForm_Action);private void MainForm_Action(object sender, ActionCancelEventArgs e){}最后調(diào)用OnAction引發(fā)事件
 
                        轉(zhuǎn)載于:https://www.cnblogs.com/huadust/archive/2011/04/07/2008739.html
總結(jié)
 
                            
                        - 上一篇: ftp put 550 Access i
- 下一篇: 只有一条输卵管还能怀孕吗?
