OmniOwl
OmniOwl

Reputation: 5709

Declaring an empty delegate vs Null Conditional

In my opinion, the fewer conditionals and checks I need to do, the better.

When I use C# a common pattern for me is declaring events something like this:

public event Action MyEvent = delegate { };

MyEvent.Invoke();

(don't sweat the details too much the empty delegate is the important part)

However I see others use:

public event Action MyEvent;

MyEvent?.Invoke();

And some tell me I should do that instead of the empty delegate. However in my opinion the empty delegate saves me a conditional check.

Is one better than the other or can I note this down as a preference in the grand scheme of things?

Upvotes: 0

Views: 26

Answers (0)

Related Questions