Checking delegates for null

后端 未结 6 2055
滥情空心
滥情空心 2021-02-04 11:48

I was reading the Essential C# 3.0 book and am wondering if this is a good way to check delegates for null?:

class Thermostat
{
    public delegate void Temperat         


        
6条回答
  •  Happy的楠姐
    2021-02-04 12:43

    There is a reason the code you've given is recommended over C. Ross's version. However, John is also right that there is still another problem if an event is unregistered in the meanwhile. The blog I linked recommends that the handler ensure they can be called even after being unregistered.

提交回复
热议问题