Is this a better way to fire/invoke events without a null check in C#?

后端 未结 4 716
庸人自扰
庸人自扰 2021-02-05 19:05

Most code I have seen uses the following way to declare and invoke event firing:

public class MyExample
{
    public event Action MyEvent; // could be an event E         


        
4条回答
  •  别跟我提以往
    2021-02-05 19:39

    It is a style thing for sure; however, I think most developers go for safety over style when it comes to null checks. There is nothing in this world that can guarantee that a bug will not creep into the system and that null check will continue to be unnecessary.

提交回复
热议问题