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;
精彩评论