title: C#: How to design a generic class so that the type parameter must inherit a certain class?
body: <p>I've written a class that looks like this:</p>
  
  <pre><code>public class MyClass&lt;T&gt;
  {
      public void doSomething()
      {
         T.somethingSpecial;
      }
  }
  </code></pre>
  
  <p>This code doesn't compile because the compiler has no idea what T is.  I would like to constrain T so that it must inherit a certain class that defines <code>somethingSpecial</code>.  Bonus points if you can tell me how to do the same thing by contraining T so that it must implement a certain interface.</p>