Alex Rivera | Logout

Impossible recursive generic class definition?

Asked 2012-03-12T07:30:18.270
9

Challenge: Please create an instance of the following class (using any type as T):

class Foo<T>
    where T : Foo<T>
{
}

You may use any technique you like; plain "new MyClass...", using reflection, hacking MSIL, whatever.

c#
Edit
Report

1 Answer

12
static class Program {
    static void Main() {
        Foo<Bar> foo = new Foo<Bar>();
    }
}
class Foo<T> where T : Foo<T> {}
class Bar : Foo<Bar> {}
answered 2012-03-12T07:58:41.347

Your Answer