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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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
Buttonand aLabel, you could add, in the constructor (afterInitializeComponent()):This will cause the label to change as the button is clicked.