Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unsubscribe lambda expression from event c# [duplicate]

I have the following code attaching event handler:

this.btnOK.Click += (s,e) => { MessageBox.Show("test");  };

Can I unsubscribe that lambda expression from the vent?

like image 961
v.chjen Avatar asked Nov 10 '22 08:11

v.chjen


1 Answers

Why don't just save the assigned lambda?

 EventHandler lambda = (s,e) => { MessageBox.Show("test");  };

 ...

 this.btnOK.Click += lambda;

 ... 

 this.btnOK.Click -= lambda;
like image 193
Dmitry Bychenko Avatar answered Nov 15 '22 00:11

Dmitry Bychenko