How to disable anonymous event?

Possible duplicate:
How to unregister an "anonymous" event handler

I have a code like this:

Binding bndTitle = this.DataBindings.Add("Text", obj, "Title"); bndTitle.Format += (sender, e) => { e.Value = "asdf" + e.Value; }; 

How to disable the Format event?

+6
c # events visual-studio-2008 disconnect
source share
1 answer

You cannot do this, unfortunately. You can create a local object to store lambda if you delete the event in the same area:

 Binding bndTitle = this.DataBindings.Add("Text", obj, "Title"); EventHandler handler = (sender, e) => { e.Value = "asdf" + e.Value; }; bndTitle.Format += handler; // ... bndTitle.Format -= handler; 
+3
source share

All Articles