I'm trying to do this:
interface IA
{
}
class A : IA
{
}
class Foo<T> where T: IA
{
}
class Program
{
static void Main( string[] args )
{
Foo<A> fooA = new Foo<A>();
Foo<IA> fooIA = fooA as Foo<IA>;
}
}
However, the cast from Foo<A> to Foo<IA> does not compile. I recall seeing covariance issues like this when casting between List<T>'s, but I didn't think it applied to simple generics like this.
What is a good work around to getting this cast to work? How do I solve this problem?