1. 重载其中一个必须两个都要重载。

2. 不能在方法中使用==或!==运算符;

 public static bool operator ==(TestRefOperatorEquals te1, TestRefOperatorEquals te2)
        {
            
/* 以下代码是错误的,因为操作符已被重载
            if (te1==null && te2==null)
            {
                return true;
            }
            if (te1 !=null )
            {
                return te1.Equals(te2);
            }
            return false;
            
*/
            
//正确的方法
            return object.ReferenceEquals(te1, te2);
        }

相关文章:

  • 2021-05-23
  • 2021-12-08
  • 2018-10-08
  • 2021-12-09
  • 2021-08-24
  • 2022-03-03
  • 2022-02-08
  • 2021-09-11
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案