Is calling an extension method on a “null” reference (i.e. event with no subscribers) evil?

前端 未结 8 738
梦谈多话
梦谈多话 2020-12-12 16:05

Evil or not evil?

public static void Raise(this EventHandler handler, object sender, EventArgs args)
{
   if (handler != null)
   {
      handler(sender, arg         


        
8条回答
  •  长情又很酷
    2020-12-12 16:30

    Not evil. I wish events worked this way by default. Can someone explain why an event with no subscribers is null?

提交回复
热议问题