I am wondering before removing the handler
OnEvent -= handler;
Do we need to determine if the handler is the null or not. When handler is null, is there any bad effect?
No, if handler
is null it's a no-op... or at least, it will be if it's a simple call to Delegate.Remove
, which has documentation including:
Returns source if value is null or if the invocation list of value is not found within the invocation list of source.
Now an actual event just has a "remove" method effectively... and that can do anything it wants. It would be a pretty poorly-implemented event which had an ill effect when passed a null handler though, as null effectively means "an empty invocation list" in delegate terms.
No, this is not a problem. It's like removing a non existing item of a collection. Nothing happens.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With