开发者

Removing anonymous event handlers [duplicate]

This question alread开发者_运维技巧y has an answer here: Closed 11 years ago.

Possible Duplicate:

C#: How to remove a lambda event handler

Is it possible to remove an event handler which was attached as anonymous function? Let's say I have an event, and I subscribe to it in this way:

TestClass classs = new TestClass ();
classs.myCustomEvent +=  (a,b) => { Console.Write(""); };

Is it possible somehow to remove this eventHandler using -= ??


It is possible, but you need to store it in a local variable first:

MyDelegate handler = (a, b) => { Console.Write(""); };
class.myCustomEvent += handler;
class.myCustomEvent -= handler;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜