title: How to determine if two generic type values are equal?
body: <p><strong>Update*</strong>
  I am so sorry... my sample code contained an error which resulted in a lot of answers I didn't understand.
  In stead of</p>
  
  <pre><code>Console.WriteLine("3. this.Equals   " + (go1.Equals(go2)));
  </code></pre>
  
  <p>I meant to write</p>
  
  <pre><code>Console.WriteLine("3. this.Equals   " + (go1.Equals(sb2)));
  </code></pre>
  
  <hr>
  
  <p>I'm trying to figure out how I can successfully determine if two generic type values are equal to each other. Based on Mark Byers' answer on <a href="https://stackoverflow.com/questions/3470145/two-net-objects-that-are-equal-dont-say-they-are">this question</a> I would think I can just use <code>value.Equals()</code> where value is a generic type.
  My actual problem is in a LinkedList implementation, but the problem can be shown with this simpler example.</p>
  
  <pre><code>class GenericOjbect&lt;T&gt; {
      public T Value { get; private set; }
      public GenericOjbect(T value) {
          Value = value;
      }
      public bool Equals(T value) {
          return (Value.Equals(value));
      }
  }
  </code></pre>
  
  <p>Now I define an instance of <code>GenericObject&lt;StringBuilder&gt;</code> containing <code>new StringBuilder("StackOverflow")</code>. I would expect to get <code>true</code> if I call <code>Equals(new StringBuilder("StackOverflow")</code> on this GenericObject instance, but I get <code>false</code>.</p>
  
  <p>A sample program showing this:</p>
  
  <pre><code>using System;
  using System.Text;
  
  class Program
  {
      static void Main()
      {
          var sb1 = new StringBuilder("StackOverflow");
          var sb2 = new StringBuilder("StackOverflow");
  
          Console.WriteLine("StringBuilder compare");
          Console.WriteLine("1. ==            " + (sb1 == sb2));
          Console.WriteLine("2. Object.Equals " + (Object.Equals(sb1, sb2)));
          Console.WriteLine("3. this.Equals   " + (sb1.Equals(sb2)));
  
          var go1 = new GenericOjbect&lt;StringBuilder&gt;(sb1);
          var go2 = new GenericOjbect&lt;StringBuilder&gt;(sb2);
  
          Console.WriteLine("\nGenericObject compare");
          Console.WriteLine("1. ==            " + (go1 == go2));
          Console.WriteLine("2. Object.Equals " + (Object.Equals(go1, sb2)));
          Console.WriteLine("3. this.Equals   " + (go1.Equals(sb2)));
          Console.WriteLine("4. Value.Equals  " + (go1.Value.Equals(sb2.Value)));
      }
  }
  </code></pre>
  
  <p>For the three methods of comparing two StringBuilder objects, only the StringBuilder.Equals instance method (the third line) returns <code>true</code>. This is what I expected. But when comparing the GenericObject objects, its Equals() method (the third line) returns <code>false</code>. Interestingly enough, the fourth compare method <em>does</em> return <code>true</code>. I'd think the third and fourth comparison are actually doing the same thing.</p>
  
  <p>I would have expected <code>true</code>. Because in the Equals() method of the GenericObject class, both <code>value</code> and <code>Value</code> are of type <code>T</code> which in this case is a <code>StringBuilder</code>. Based on Mark Byers' answer in <a href="https://stackoverflow.com/questions/3470145/two-net-objects-that-are-equal-dont-say-they-are">this question</a>, I would've expected the <code>Value.Equals()</code> method to be using the StringBuilder's Equals() method. And as I've shown, the StringBuilder's Equal() method does return <code>true</code>.</p>
  
  <p>I've even tried </p>
  
  <pre><code>public bool Equals(T value) {
      return EqualityComparer&lt;T&gt;.Default.Equals(Value, value);
  }
  </code></pre>
  
  <p>but that also returns false.</p>
  
  <p>So, two questions here:</p>
  
  <ol>
  <li>Why doesn't the code return <code>true</code>?</li>
  <li>How could I implement the <code>Equals</code> method so it <em>does</em> return <code>true</code>?</li>
  </ol>