Raising C# events with an extension method - is it bad?

后端 未结 6 1267
执念已碎
执念已碎 2020-12-02 10:55

We\'re all familiar with the horror that is C# event declaration. To ensure thread-safety, the standard is to write something like this:

public event EventH         


        
6条回答
  •  囚心锁ツ
    2020-12-02 11:49

    Less code, more readable. Me like.

    If you're not interested in performance you can declare your event like this to avoid the null check:

    public event EventHandler SomethingHappened = delegate{};
    

提交回复
热议问题