Someone mentioned to me that c# supports to use lambda expression as event handler, can anyone share with me some reference on this?
A code snippet is preferred.
You can use a lambda expression to build an anonymous method, which can be attached to an event.
For example, if you make a Windows Form with a Button
and a Label
, you could add, in the constructor (after InitializeComponent()
):
this.button1.Click += (o,e) =>
{
this.label1.Text = "You clicked the button!";
};
This will cause the label to change as the button is clicked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With