Understanding a parameter in C # code

IntelliSense says the lambda parameter eais LoadStringCompletedEvent Args. It is clear, but the parameter sis defined only as "object s". Can anyone explain the purpose of this parameter?

WebClient client = new WebClient();

        client.DownloadStringCompleted += (s, ea) => 
                     { XDocument document = XDocument.Parse(ea.Result);
                        // ... Do something else...
                      };
+3
source share
3 answers

EventHandlers in .NET usually have the form

void MyEventHandler(object sender, EventArgs e) { ... }

An argument senderis the object in which the event occurred. Since it can be anything, the object is used. The EventArgs argument is usually either itself System.EventArgsor its subclass. In your case, this is a subclass.

+2
source

AFAIK, that the object s is usually known as the "sender", therefore, s for the sender - i.e. the object that generates the event, aka, the source.

, .

+4

public delegate void DownloadStringCompletedEventHandler (    ,   DownloadStringCompletedEventArgs e )

s " ".

http://msdn.microsoft.com/en-us/library/system.net.downloadstringcompletedeventhandler.aspx

+2
source

Source: https://habr.com/ru/post/1788370/


All Articles