Possible Duplicate:
C# Adding and Removing Anonymous Event Handler
suppose I have an Action delegate declared this way:
public event Action<MenuTraverser.Actions> menuAction;
I am associating a method to it this way:
menuInputController.menuAction += (MenuTraverser.Actions action) => this.traverser.OnMenuAction(action);
Now, all works fine, but in certain situation I need to remove the delegated method and I don’t know how.
I tried this way but doesn’t work:
menuInputController.menuAction -= (MenuTraverser.Actions action) => this.traverser.OnMenuAction(action);
How can I do such a thing? I need that my method OnMenuAction will be no longer called.
Since your signature seems to match (assuming that you have a
voidreturn type), you shouldn’t need to add an anonymous function but you can use the method group directly:And in this case unsubscribing should work as well: