title: Differences between IEquatable<T>, IEqualityComparer<T>, and overriding .Equals() when using LINQ on a custom object collection?
body: <p>I'm having some difficulty using Linq's .Except() method when comparing two collections of a custom object.</p>
  
  <p>I've derived my class from <code>Object</code> and implemented overrides for <code>Equals()</code>, <code>GetHashCode()</code>, and the operators <code>==</code> and <code>!=</code>. I've also created a <code>CompareTo()</code> method.</p>
  
  <p>In my two collections, as a debugging experiment, I took the first item from each list (which is a duplicate) and compared them as follows:</p>
  
  <pre><code>itemListA[0].Equals(itemListB[0]);     // true
  itemListA[0] == itemListB[0];          // true
  itemListA[0].CompareTo(itemListB[0]);  // 0
  </code></pre>
  
  <p>In all three cases, the result is as I wanted. However, when I use Linq's Except() method, the duplicate items are <em>not</em> removed:</p>
  
  <pre><code>List&lt;myObject&gt; newList = itemListA.Except(itemListB).ToList();
  </code></pre>
  
  <p>Learning about how Linq does comparisons, I've discovered various (conflicting?) methods that say I need to inherit from <code>IEquatable&lt;T&gt;</code> or <code>IEqualityComparer&lt;T&gt;</code> etc.</p>
  
  <p>I'm confused because when I inherit from, for example, <code>IEquatable&lt;T&gt;</code>, I am required to provide a new <code>Equals()</code> method with a different signature from what I've already overridden. Do I need to have two such methods with different signatures, or should I no longer derive my class from <code>Object</code>?</p>
  
  <p>My object definition (simplified) looks like this:</p>
  
  <pre><code>public class MyObject : Object
  {
      public string Name {get; set;}
      public DateTime LastUpdate {get; set;}
  
      public int CompareTo(MyObject other)
      {
          // ...
      }
  
      public override bool Equals(object obj)
      {
          // allows some tolerance on LastUpdate
      }
  
      public override int GetHashCode()
      {
          unchecked
          {
              int hash = 17;
              hash = hash * 23 + Name.GetHashCode();
              hash = hash * 23 + LastUpdate.GetHashCode();
              return hash;
          }
      }
  
      // Overrides for operators
  }
  </code></pre>
  
  <p>I noticed that when I inherit from <code>IEquatable&lt;T&gt;</code> I can do so using <code>IEquatable&lt;MyObject&gt;</code> or <code>IEquatable&lt;object&gt;</code>; the requirements for the <code>Equals()</code> signature change when I use one or the other. What is the recommended way?</p>
  
  <p><strong>What I am trying to accomplish:</strong></p>
  
  <p>I want to be able to use Linq (Distinct/Except) as well as the standard equality operators (<code>==</code> and <code>!=</code>) without duplicating code. The comparison should allow two objects to be considered equal if their name is identical <em>and</em> the <code>LastUpdate</code> property is within a number of seconds (user-specified) tolerance.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Showing <code>GetHashCode()</code> code.</p>