我有这段代码:
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。
请告知。
答案 0 :(得分:2)
您需要提供AsyncCallback
类型的对象。试试这个:
request.BeginGetResponse(new AsyncCallback(callback), null);