Why use EventArgs.Empty instead of null?

前端 未结 6 1874
悲哀的现实
悲哀的现实 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 10:13

    I believe the reasoning behind the NOT NULL is that when passed as a parameter, it is not expected for the method to need to potentially handle a null reference exception.

    If you pass null, and the method tries to do something with e it will get a null reference exception, with EventArgs.Empty it will not.

提交回复
热议问题