2010-11-02 83 views
1

我有這樣的代碼:HttpWebRequest的BeginGetResponse Action委託lambda表達式作爲參數

protected static string MakeGetRequest(string url, Action<IAsyncResult> callback) 
    { 
     var request = (HttpWebRequest)HttpWebRequest.Create(new Uri(url)); 
     request.BeginGetResponse(callback, null);    
    } 

這將無法編譯,我得到了BeginGetResponse行錯誤:

無法從「System.Action」轉換爲'System.AsyncCallback'

我想傳遞一個函數作爲我的AsyncCallback。

請指教。

回答

2

您需要提供AsyncCallback類型的對象。試試這個:

request.BeginGetResponse(new AsyncCallback(callback), null); 
+0

完美,謝謝。 – 2010-11-02 21:42:11

相關問題