title: overload == (and != , of course) operator, can I bypass == to determine whether the object is null
body: <p>when I try to overload operator == and != in C#, and override Equal as recommended, I found I have no way to distinguish a normal object and null. For example, I defined a class Complex.</p>
  
  <pre><code>public static bool operator ==(Complex lhs, Complex rhs)
  {
      return lhs.Equals(rhs);
  }
  
  public static bool operator !=(Complex lhs, Complex rhs)
  {
      return !lhs.Equals(rhs);
  }
  
  public override bool Equals(object obj)
  {
      if (obj is Complex)
      {
          return (((Complex)obj).Real == this.Real &amp;&amp;
                     ((Complex)obj).Imaginary == this.Imaginary);
      }
      else
      {
          return false;
      }
  }
  </code></pre>
  
  <p>But when I want to use</p>
  
  <pre><code>if (temp == null)
  </code></pre>
  
  <p>When temp is really null, some exception happens. And I can't use == to determine whether the lhs is null, which will cause infinite loop.</p>
  
  <p>What should I do in this situation.</p>
  
  <p>One way I can think of is to us some thing like Class.Equal(object, object) (if it exists) to bypass the == when I do the check.</p>
  
  <p>What is the normal way to solve the problem?</p>
  
  <p>Thank you.</p>