문제

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?

도움이 되었습니까?

해결책

Why don't just save the assigned lambda?

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

 ...

 this.btnOK.Click += lambda;

 ... 

 this.btnOK.Click -= lambda;

다른 팁

You cannot un-assign that event because it is a anonymous method.

Give it a name and you are ready to unsubscribe.

you can do :

this.btnOK.Click = null;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top