Compartir a través de


Pop Quiz!

Ok class.  Get out your pencils for another pop quiz. 
Without using anything beyond your mind, answer the following question:

Consider the following code:

 public class A<T1>
{
    public T1 a;

    public class B<T2> : A<T2>
    {
        public T1 b;

        public class C<T3> : B<T3>
        {
            public T1 c;
        }
    }
}
 class PopQuiz
{
    static void Main()
    {
        A<int>.B<char>.C<bool> o = new A<int>.B<char>.C<bool>();
        System.Console.WriteLine(o.a.GetType().FullName);
        System.Console.WriteLine(o.b.GetType().FullName);
        System.Console.WriteLine(o.c.GetType().FullName);
    }
}

What gets printed when you execute the Main method of PopQuiz?  No cheating!

Try to figure it out.  Write down what you think the answer is, then check it versus what the actual compiled code prints.

For those of you who didn't get it... can you figure out why the answer looks the way it does?

For those of you who did get it (and probably cheated then ;-)  ), can you explain how you got your answer?

Good luck!

Comments