I was wiring up an event to use a lambda which needed to remove itself after triggering. I couldn\'t do it by inlining the lambda to the += event (no accessable variable to
In general, delegates can't be cast because they have no inheritance tree defining which casts are valid. To that end, you have two choices:
EventHandler instead of the ActionUse an inline declaration.
// option 1: local variable
EventHandler eh = (o, ea) => { /* [snip] */ };
obj.event += eh;
obj.event -= eh;
// option 2: inline declaration
obj.event += (o, ea) => { /* [snip] */ };