title: understanding nested generic classes in C# with quiz
body: <p>While talking with a colleague about C#, he showed me some C# code which I had to predict the output of. This looked simple in the first place, but it wasn't. I can not really understand why C# acts this way.</p>
  
  <p>The code:</p>
  
  <pre><code>public class A&lt;T1&gt;
  {
      public T1 a;
  
      public class B&lt;T2&gt; : A&lt;T2&gt;
      {
          public T1 b;
  
          public class C&lt;T3&gt; : B&lt;T3&gt;
          {
              public T1 c;
          }
      }
  }
  
  class Program
  {
      static void Main(string[] args)
      {
          A&lt;int&gt;.B&lt;char&gt;.C&lt;bool&gt; o = new A&lt;int&gt;.B&lt;char&gt;.C&lt;bool&gt;();
  
          Console.WriteLine(o.a.GetType());
          Console.WriteLine(o.b.GetType());
          Console.WriteLine(o.c.GetType());
  
          Console.ReadKey();
      }
  }
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>System.Boolean
  System.Char
  System.Int32
  </code></pre>
  
  <p>Correct me if I'm wrong, but I understand that <code>o.a</code> is of type bool because <code>C&lt;T3&gt;</code> inherits from <code>B&lt;T3&gt;</code> and <code>B&lt;T2&gt;</code> inherits from <code>A&lt;T2&gt;</code>. And I can also slightly understand that <code>o.c</code> is of type int because the type of <code>c</code> is <code>T1</code> which it gets from the outer class (I think).</p>
  
  <p>My head is almost exploding when I try to figure out why <code>o.b</code> is of type char. Can some one explain this to me?</p>