-1

From m$ site. I don't get the += o,a what is that ???

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);
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
JAMES
  • 27
  • 4
  • I suggest you read up on delegates, events, and lambda expressions and that should just about cover it. – juharr Aug 02 '17 at 19:34
  • 2
    Possible duplicate of [Understanding events and event handlers in C#](https://stackoverflow.com/questions/803242/understanding-events-and-event-handlers-in-c-sharp) – Andrew Sun Aug 02 '17 at 20:12

2 Answers2

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

This is assigning an anonymous delegate to the wc.OpenReadCompleted event. The (o,a) part are the method parameters.

o is object. a is the EventArgs

Stuart
  • 3,949
  • 7
  • 29
  • 58
0

As I can see from the signature of OpenReadCompletedEventHandler (which should be used to subscribe to OpenReadCompleted event), o is a sender and a is an instance of OpenReadCompletedEventArgs.

In general this approach of subscription to events is basically instantiating a delegate using a lambda expression, one can do this since C# 3.0.