特殊值 null 与所有引用类型兼容,它指示缺少实例。因此只要判断应用是否等于null 就行了: if (ref == null ) {};

解决方案 »

  1.   

    不对。public class test
    {
    public static bool operator==( test a, test b )
    {
    return true;
    }};
    test a = null;
    test b = new test();if( a == b )
    {
    }在上面的 a==b中,调用了自定义的operator==,结果总是返回为true,虽然实际上有一个值为null,所以应该存在一个函数判断一个值为否为null,而不是简单的比较。
      

  2.   

    我靠!老大,你对==这个operator的重载函数里面,就是始终返回true,然后你比较a==b,当然始终是true了!!!哈哈!给分!if(a==null)其实就可以了!
      

  3.   

    拜托,你跟踪一下,即使是
    a == null也会调用operator==()这个函数。
      

  4.   

    我找到了,是ReferenceEquals()这个函数。