title: When overloading the equality operator, what's the best way to handle null values?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/73713/how-do-i-check-for-nulls-in-an-operator-overload-without-infinite-recursion">How do I check for nulls in an ‘==’ operator overload without infinite recursion?</a>  </p>
  </blockquote>
  
  
  
  <p>Say I have a type like this:</p>
  
  <pre><code>public class Effect
  {
      public static bool operator == ( Effect a, Effect b )
      {
          return a.Equals ( b );
      }
  
      public static bool operator != ( Effect a, Effect b )
      {
          return !a.Equals ( b );
      }
  
      public bool Equals ( Effect effect )
      {
          return this.TypeID.Equals ( effect.TypeID );
      }
  
      public override bool Equals ( object obj )
      {
          return this.TypeID.Equals ( ( ( Effect ) obj ).TypeID );
      }
  }
  </code></pre>
  
  <p>What's the most robust and cleanest way to handle null values?</p>
  
  <p>I am not sure if I have to check for null for both the current instance (<code>this</code>) and the passed instance <code>(effect/obj)</code>? If I have null for the current instance (<code>this</code>), would the compiler still call effect.Equals or Object.Equals?</p>
  
  <p>Also either way where should the null checks be done? I am assuming only inside the Equals methods, and not the equality operators (<code>==, !=</code>).</p>