title: Using c# generics in a nested class
body: <p>Consider the following class structure:</p>
  
  <pre><code>public class Foo&lt;T&gt;
  {
      public virtual void DoSomething()
      {
      }
  
      public class Bar&lt;U&gt; where U : Foo&lt;T&gt;, new()
      {
          public void Test()
          {
              var blah = new U();
              blah.DoSomething();
          }
      }
  }
  
  public class Baz
  {
  }
  
  public class FooBaz : Foo&lt;Baz&gt;
  {
      public override void DoSomething()
      {
      }
  }
  </code></pre>
  
  <p>When I go to use the nested class, I have something like the following:</p>
  
  <pre><code>var x = new FooBaz.Bar&lt;FooBaz&gt;();
  </code></pre>
  
  <p>It seems redundant to have to specify it twice.  How would I create my class structure such that I can do this instead:</p>
  
  <pre><code>var x = new FooBaz.Bar();
  </code></pre>
  
  <p>Shouldn't there be some way on the where clause of the nested class to say that U is always the parent?  How?</p>
  
  <hr>
  
  <p>Update: Added methods for DoSomething() above to address some of the comments.  It's important that when I call DoSomething, it addresses the overridden version.  If I just use Foo instead of U, then the base implementation is called instead.</p>