2017-08-02 60 views
-1

来自m $网站。我没有得到+ = o,那是什么?关于匿名功能的语法问题

private void GetResponse(Uri uri, Action<Response> callback) 
{ 
    WebClient wc = new WebClient(); 

    wc.OpenReadCompleted += (o, a) => 
    { 
     if (callback != null) 
     { 
      DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Response)); 
      callback(ser.ReadObject(a.Result) as Response); 
     } 
    }; 
    wc.OpenReadAsync(uri); 
} 
+0

我建议你阅读代表,事件和lambda表达式,这应该只是关于它。 – juharr

+2

[了解C#中的事件和事件处理程序]的可能的重复(https://stackoverflow.com/questions/803242/understanding-events-and-event-handlers-in-c-sharp) –

回答

1
wc.OpenReadCompleted += (o, a) => { } 

这是为wc.OpenReadCompleted事件分配一个匿名委托。 (o,a)部分是方法参数。

o是对象。 a是EventArgs