static void Main(string[] args) { MultiCastDelegate MCD = new MultiCastDelegate(); MYDelegate m = new MYDelegate(MCD.Hello1); m += MCD.Hello2; m.Invoke(); MultiCastDelegate2 mcd2 = new MultiCastDelegate2(); IntDelegate IDel = new IntDelegate(mcd2.add); IDel += mcd2.sub; IDel += mcd2.div; IDel.Invoke(100, 200); Console.WriteLine(); }
/// <summary> /// http://www.soaspx.com/dotnet/csharp/csharp_20120220_8610.html /// </summary>http://www.fengfly.com/plus/view-173114-1.html /// <param name="uRecvPort"></param> /// <param name="myDelegate"></param> /// <param name="iRecvBuf"></param> /// <returns></returns> public bool BindSocket(int uRecvPort, MYDelegate myDelegate, int iRecvBuf) { //得到本机IP,设置UDP端口号 m_ip = new IPEndPoint(IPAddress.Any, uRecvPort); Reconnect(); //对于不存在的IP地址,加入此行代码后,可以在指定时间内解除阻塞模式限制 // m_newsock.SetSocketOption(SocketOptionLevel.Udp, SocketOptionName., 100); RecvDelegate = myDelegate; recvData = new byte[iRecvBuf]; recvThread = new Thread(RecvDataThread); recvThread.IsBackground = false; recvThread.Start(); return(true); }