thi...">

What is the meaning of "+ = (s, e)" in the code?

What is += ( s, e ) in the code?

example:

this.currentOperation.Completed += ( s, e ) => this.CurrentOperationChanged();

+4
source share
4 answers

These codes add an event listener in the form of a Lambda expression. s stands for sender and e stands for EventArgs . Lambda for

 private void Listener(object s, EventArgs e) { } 
+5
source

This is a way to attach an event handler using a Lambda expression.

For instance:

 button.Click += new EventHandler(delegate (Object s, EventArgs e) { //some code }); 

It can be rewritten using lambda as follows:

 button.Click += (s,e) => { //some code }; 

One comment here. There is no need to write 's' and 'e'. You can use any two letters, for example.

 button.Click += (o,r) => {}; 

The first parameter will represent the object that triggered the event, and the second is the data that can be used in the event handler.

+17
source

This is the assignment of the delegate instance (the beginning of the lambda expression) to the list of event calls. s, e represents the sender and EventArgs parameters of the event delegate type.

See http://msdn.microsoft.com/en-us/library/ms366768.aspx for more details.

+3
source

This is an abbreviation for an event handler. s โ†’ the sender of the object and e โ†’ some type of EventArgs.

It can also be rewritten as:

 public void HandlerFunction(object sender, EventArgs e) { this.loaded = true; } 
+3
source

All Articles