C# object is not null but (myObject != null) still return false

后端 未结 8 1946
不知归路
不知归路 2020-12-05 10:57

I need to do a comparaison between an object and NULL. When the object is not NULL I fill it with some data.

Here is the code :

 if (region != null)
         


        
8条回答
  •  旧时难觅i
    2020-12-05 11:26

    So is it that these checks here are not right:

    public static bool operator !=(Region r1, Region r2)
    {
        if (object.ReferenceEquals(r1, null))
        {
            return false;
        }
        if (object.ReferenceEquals(r2, null))
        {
            return false;
        }
    ...
    

提交回复
热议问题