what is the meaning of this

What part has you puzzled?
 
That is an event handler registration and it is using a lambda as the event handler rather than a named method. Using a more common event as an example, if you want to handle the Click event of a Button, the "traditional" way to do that would be to start with a method that had the appropriate signature and performed the action you wanted:
C#:
private void SayHello(object sender, EventArgs e)
{
    MessageBox.Show("Hello");
}
You could then register that method as the handler for the Click event of a Buttonlike so:
C#:
var btn = new Button();

btn.Click += SayHello;
You specify the object and the event and then use the += operator to add a delegate to a method with the appropriate signature. If you were to create a WinForms app and double-click a Button to generate a Click event handler, you'd find code like that in the designer code file. The part on the right is known as a method group. Basically, using the name of the method alone, without parentheses, creates a delegate for that method, i.e. an object that contains a reference to that method. You can then pass that object around and anywhere you have a reference to it, you can invoke the method it refers to, even if you don't have a reference to the object that the method is a member of. That's the point of delegates: to allow you to invoke a method without having to care where that method is declared. In this case, when the Button raises its Click event, it can invoke the handlers for that event via those delegates and doesn't have to care where the methods themselves are declared.

Method groups are only one way to create a delegate though. They are used to create delegates for named methods but C# first introduced anonymous methods and then refined the concept with lambda expressions. Using the example above, you could use a lambda expression instead of a named method and a method group. You basically strip out everything that isn't essential from the method and then use it inline:
C#:
var btn = new Button();

btn.Click += (sender, e) => { MessageBox.Show("Hello"); };
Hopefully you can see how that corresponds to what we had in the earlier example. In fact, because the method is only one line, it can be simplified further:
C#:
var btn = new Button();

btn.Click += (sender, e) => MessageBox.Show("Hello");
That's basically the same thing that is happening in your code. Mind you, the fact that the method name starts with "on" and also starts with a lower-case letter and the method parameters are not an object named sender and an EventArgs named e makes it look more like Java or JavaScript than C#. You don't have to stick to that convention in C# but you absolutely should.
 
Back
Top Bottom