In C#, why can't I test if a event handler is null anywhere outside of the class that it's defined?

后端 未结 7 1648
Happy的楠姐
Happy的楠姐 2020-12-24 05:58

I am sure that I am just not understanding something fundamental about events and/or delegates in C#, but why can\'t I do the Boolean tests in this code sample:



        
7条回答
  •  爱一瞬间的悲伤
    2020-12-24 06:28

    Here's a slightly different question

    What value is there in testing an externally defined event for null?

    As an external consumer of an event you can only do 2 operations

    • Add a handler
    • Remove a handler

    The null or non-nullness of the event has no bearing on these 2 actions. Why do you want to run a test which provides no perceivable value?

提交回复
热议问题