client.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveMessage), client);其中ReceiveMessage是回调函数,我想让ReceiveMessage传参数该怎么办client.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveMessage(ar,label1)), client);会报错,能传参数吗
2 回答
芜湖不芜
TA贡献1796条经验 获得超7个赞
AsyncCallback委托只接受一个 System.IAsyncResult 类型的参数。
如果需要传递参数我一般会直接写匿名函数,比如
12345678910111213 | public int Receive() { byte [] a = null ; int b; string c; client.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, (System.IAsyncResult ar) => { a = c.Split( ' ' ); b = 100; // 怎么写都可以 }, client); } |
- 2 回答
- 0 关注
- 974 浏览
添加回答
举报
0/150
提交
取消