Possible Duplicates:
Why cannot C# generics derive from one of the generic type parameters like they can in C++ templates?
In C# 4.0, is it possible to derive a class from a generic type parameter?
I'm trying to create a generic class that inherits from its generic type (in 1.Attempt). Looks like it's impossible. But in other attempt i must cast the object. Any design solution to that problem?
// #1 Attempt
public interface IFoo { }
public class Generic<T> : T { }
public void play ()
{
IFoo genfoo = new Generic<IFoo> ();
}
.
// #2 Attempt. Castable solution
public interface IAnything { }
public interface IFoo2 : IAnything { }
public class Generic2<T> : IAnything { }
public void play2 ()
{
IFoo2 genFoo = (IFoo2) new Generic2<IFoo2> ();
}