nested generic class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • puzzlecracker

    #1

    nested generic class

    How will this actually work:

    public class Foo<T>
    {

    public class Bar<T>
    {
    private T t;

    }
    }


    public class Test
    {
    public static void Main(string []args)
    {
    Foo<intfoo=new Foo<int>(); ///???

    }
    }
    will this cause the nested Bar class, at run time, to become closed
    time using int?

    Becoming something like this:

    public class Foo<int>
    {

    public class Bar<int>
    {
    private T t;

    }
    }

    Thanks
  • Peter Duniho

    #2
    Re: nested generic class

    On Sat, 18 Oct 2008 11:49:00 -0700, puzzlecracker <ironsel2000@gm ail.com>
    wrote:
    How will this actually work:
    Looks like another great opportunity for you to fire up Visual Studio and
    try it yourself.

    If after doing that you have some specific question about what _does_
    happen, that would be a question worth answering.

    Pete

    Comment

    • Jon Skeet [C# MVP]

      #3
      Re: nested generic class

      puzzlecracker <ironsel2000@gm ail.comwrote:
      How will this actually work:
      >
      public class Foo<T>
      {
      >
      public class Bar<T>
      {
      private T t;
      >
      }
      }
      >
      public class Test
      {
      public static void Main(string []args)
      {
      Foo<intfoo=new Foo<int>(); ///???
      >
      }
      }
      will this cause the nested Bar class, at run time, to become closed
      time using int?
      Well you haven't referred to a nested Bar class at all. However, Bar
      defines its own type parameter, which hides Foo's. They're separate
      type parameters though.

      In other words, you can specify Foo<string>.Bar <int>.

      For further nested generic type weirdness, see this post from Cyrus:
      http://blogs.msdn.com/cyrusn/archive...01/446431.aspx

      --
      Jon Skeet - <skeet@pobox.co m>
      Web site: http://www.pobox.com/~skeet
      Blog: http://www.msmvps.com/jon.skeet
      C# in Depth: http://csharpindepth.com

      Comment

      Working...