title: C# generic constraint: type parameter on the class inherits type parameter on the method?
body: <p>I have a generic class, on which I define a method that should take arguments of another type, but only if the other type implements  the type parameter of the class. However, this won't compile:</p>
  
  <pre><code>class GenericClass&lt;TClass&gt;
  {
      public void DoSomething&lt;TMethod&gt;(TMethod input) where TClass : TMethod
      {
          // ...
      }
  }
  </code></pre>
  
  <p>I get a compiler error on <code>TClass</code> in the constraint on the method. Is there another way to specify this?</p>
  
  <p><strong>Clarification:</strong><br>
  I am under the impression that <code>TMethod : TClass</code> means that <code>TMethod</code> must inherit or implement <code>TClass</code> (depending on whether <code>TClass</code> is a concrete type or an interface). In other, slightly unconventional, notation <code>TMethod &gt; TClass</code> (meaning <code>TMethod</code> is a superset of <code>TClass</code>).</p>
  
  <p>What I want here, is that <code>TMethod</code> should only be a valid type if <code>TClass</code> inherits or implements it, i.e. <code>TClass &gt; TMethod</code>. Will <code>TMethod : TClass</code> do that as well?</p>
  
  <p>(One of the answers states that <code>TMethod : TClass</code> requires <code>TMethod</code> to be <em>assignable from</em> <code>TClass</code>. I'm not sure if that meets my requirements, but if it does, please explain in more detail what <em>being assignable from</em> means, since if it helps me I've probably misunderstood it...)</p>