Suppose we have a class that implements an interface
class MyParaClass : IMyParaInterface
And another class named MyObject which takes generic T
class MyObject<T> where T: IMyParaInterface
Now I have a method that accepts this parameter
Print(MyObject<IMyParaInterface> parameter)
When I get an object which type is MyObject<MyParaClass>
, and try to pass this to Print
method,Build fails because it can not convert MyObject<MyParaClass>
to MyObject<IMyParaInterface>
I thought there should be not an issue as MyParaClass
implements IMyParaInterface
.How to solve this or get around?