Why use EventArgs.Empty instead of null?

前端 未结 6 1890
悲哀的现实
悲哀的现实 2020-12-25 09:28

I recall reading, on multiple occasions and in multiple locations, that when firing the typical event:

protected virtual OnSomethingHappened()
{
    this.Som         


        
6条回答
  •  南笙
    南笙 (楼主)
    2020-12-25 09:55

    If you're using a general-purpose method which has the EventHandler signature that's called from any event handler and is passed both the object sender and EventArgs e, it can call e.ToString(), e.g., for logging events, without worrying about a null pointer exception.

提交回复
热议问题