Being accustomed to VB.NET, I'm used to "just raise events". Sure, custom events differ, but with "regular" events - I don't need to check if the delegate is Nothing
before raising.
With C#, I find myself repeating this pattern:
if (myHandler != null)
{
myHandler(this, new EventArgs());
}
I was thinking that the following pattern might prove more elegant:
- myHandler is initialized with an empty lambda:
myHandler = (sender, e) => { };
- myHandler is expected never to be null, so raising would simply become:
myHandler(this, new EventArgs());
Would this pattern be more or less performant than the previous one? Are there other significant considerations I should take into account?