C# 委托

来源:互联网 发布:unity3d 安卓sdk下载 编辑:程序博客网 时间:2024/06/03 10:36


public delegate void SendMsgDel(string strMsg);  //定义委托SendMsgDel SendMsgDelInstance;  //声明委托对象。SendMsgDelInstance += SetMsgText1;  //将SetMsgText1 函数 注册到委托对象中。SendMsgDelInstance += SetMsgText2;  //将SetMsgText2 函数 注册到委托对象中。SendMsgDelInstance(DateTime.Now.ToString());  //执行委托对象中所有注册的函数。可以在声明委托的类的内部和外部调用。事件只能在类内部调用。public void SetMsgText1(string str){   this.txtMessage.Text = " 委托:" + str;}public void SetMsgText2(string str){   this.txtMessage.Text = " 委托:" + str;}



原创粉丝点击