title: Equality operator overloading in struct and classes
body: <p>If I do the overloading of <code>operator ==</code> for a class, I must perform some checks before comparing the fields:</p>
  <ul>
  <li><p>if both arguments are null, or both arguments are the same instance, then returns true</p>
  <p>Example: <code>if (System.Object.ReferenceEquals(arg1, arg2)) return true;</code></p>
  </li>
  <li><p>if one is null, but not both, then returns false</p>
  <p>Example: <code>if (((object)arg1 == null) || ((object)arg2 == null)) return false;</code></p>
  </li>
  </ul>
  <p>Indeed, if I have a struct and I want to do the overloading of <code>operator ==</code>, these checks are not necessary, rather they are useless, for the following reasons: a struct is a <em>value type</em>, so it can not be null, for example <code>DateTime date = null;</code> is not valid, because <code>DateTime</code> (that is a struct) is not a reference type, so you can not compare two <code>DateTime</code>, one of which is set to <code>null</code>.</p>
  <p>I created a simple struct <code>Point2D</code> with <code>operator ==</code>, then I compare an instance of <code>Point2D</code> with <code>null</code>:</p>
  <pre><code>Point2D point = new Point2D(0,0);
  Console.WriteLine((point == null));
  </code></pre>
  <ol>
  <li><p>Obviously the <code>operator ==</code> it is not called, but the comparison returns <code>False</code>. Which method is called?</p>
  </li>
  <li><p>The <a href="http://msdn.microsoft.com/en-us/library/ms173147%28v=vs.80%29.aspx" rel="noreferrer">documentation</a> states that overloading this operator in not-immutable types is not recommended. Why?</p>
  </li>
  </ol>