title: Operator '==' cannot be applied to operands of type 'T' and 'T'
body: <p>In the code-sample below, the compiler complains on <code>x.Id == reference.Id</code>:</p>
  
  <blockquote>
    <p>Operator '==' cannot be applied to operands of type 'TId' and 'TId'</p>
  </blockquote>
  
  <p>Similar questions have been asked on SO and they're solved by replacing the <code>==</code>-operator with <code>IEquatable&lt;&gt;</code> + <code>Equals</code> or <code>EqualityComparer&lt;TEnum&gt;.Default</code>.</p>
  
  <p>However, both solutions don't work for me for reasons that are not important to this question.</p>
  
  <p><strong>I'm not looking for a replacement for the <code>==</code> operator, I'm looking for an explanation why the equality operator doesn't work for generic types.</strong></p>
  
  <pre><code>public class Object&lt;TId&gt;
  {
      public TId Id { get; set; }
  
      // Some other object properties...
  }
  
  public class ObjectReference&lt;TId&gt;
  {
      public TId Id { get; set; }
  }
  
  public class ObjectStore&lt;TId&gt;
  {
      private List&lt;Object&lt;TId&gt;&gt; _store = new List&lt;Object&lt;TId&gt;&gt;();
  
      public Object&lt;TId&gt; FindByReference(ObjectReference&lt;TId&gt; reference)
      {
          return _store.FirstOrDefault(x =&gt; x.Id == reference.Id);
      }
  }
  </code></pre>