title: How are C# Generics implemented?
body: <p>I had thought that Generics in C# were implemented such that a new class/method/what-have-you was generated, either at run-time or compile-time, when a new generic type was used, similar to C++ templates (which I've never actually looked into and I very well could be wrong, about which I'd gladly accept correction).</p>
  
  <p>But in my coding I came up with an exact counterexample:</p>
  
  <pre><code>static class Program {
      static void Main()
      {
          Test testVar = new Test();
  
          GenericTest&lt;Test&gt; genericTest = new GenericTest&lt;Test&gt;();
          int gen = genericTest.Get(testVar);
  
          RegularTest regTest = new RegularTest();
          int reg = regTest.Get(testVar);
  
          if (gen == ((object)testVar).GetHashCode())
          {
              Console.WriteLine("Got Object's hashcode from GenericTest!");
          }
          if (reg == testVar.GetHashCode())
          {
              Console.WriteLine("Got Test's hashcode from RegularTest!");
          }
      }
  
      class Test
      {
          public new int GetHashCode()
          {
              return 0;
          }
      }
  
      class GenericTest&lt;T&gt;
      {
          public int Get(T obj)
          {
              return obj.GetHashCode();
          }
      }
  
      class RegularTest
      {
          public int Get(Test obj)
          {
              return obj.GetHashCode();
          }
      }
  }
  </code></pre>
  
  <p>Both of those console lines print.</p>
  
  <p>I know that the actual reason this happens is that the virtual call to Object.GetHashCode() doesn't resolve to Test.GetHashCode() because the method in Test is marked as new rather than override. Therefore, I know if I used "override" rather than "new" on Test.GetHashCode() then the return of 0 would polymorphically override the method GetHashCode in object and this wouldn't be true, but according to my (previous) understanding of C# generics it wouldn't have mattered because every instance of T would have been replaced with Test, and thus the method call would have statically (or at generic resolution time) been resolved to the "new" method.</p>
  
  <p>So my question is this: <strong>How are generics implemented in C#?</strong> I don't know CIL bytecode, but I do know Java bytecode so I understand how Object-oriented CLI languages work at a low level. Feel free to explain at that level.</p>
  
  <p>As an aside, I thought C# generics were implemented that way because everyone always calls the generic system in C# "True Generics," compared to the type-erasure system of Java.</p>