title: Generics and casting
body: <pre><code>class B : A {}
  class Sub&lt;T&gt; where T:A
  {
  //...
  }
  </code></pre>
  
  <p>I want to store Sub instances in a collection. </p>
  
  <pre><code>var c = new List&lt;Sub&lt;A&gt;&gt;();
  c.Add(new Sub&lt;B&gt;()); //doesn't work
  </code></pre>
  
  <p>However, to get it to actually work, I have to declare an interface and store instances of that interface.</p>
  
  <pre><code>interface IBase
  {
      void DoStuff(A a);
  }
  
  var c = new List&lt;IBase&gt;();
  c.Add(new Sub&lt;B&gt;()); //works
  </code></pre>
  
  <p>Is there a more elegant way of doing this?</p>