Suppose the following:
interface IBase { }
interface IChild : IBase { }
interface IFace<in T> where T : IBase { }
private class MyClass : IFace<IBase> { }
void Do1()
{
// This is fine
IFace<IChild> impl = new MyClass();
}
void Do2<T>() where T : IBase
{
// This is not
IFace<T> impl = new MyClass();
}
Why is that? Isn't T
in Do2
guaranteed to inherit from/implement IBase?
Edit: forgot where clause in IFace