client.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveMessage), client);其中ReceiveMessage是回調(diào)函數(shù),我想讓ReceiveMessage傳參數(shù)該怎么辦client.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveMessage(ar,label1)), client);會(huì)報(bào)錯(cuò),能傳參數(shù)嗎
2 回答

蕪湖不蕪
TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超7個(gè)贊
AsyncCallback委托只接受一個(gè) System.IAsyncResult 類型的參數(shù)。
如果需要傳遞參數(shù)我一般會(huì)直接寫匿名函數(shù),比如
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 關(guān)注
- 1052 瀏覽
添加回答
舉報(bào)
0/150
提交
取消