Bit surprised why this does not work
Is this a limitation of the compiler or does it make good sense not to support it?
public class Class1<T> : IInterface
where T : Test2
{
public T Test { get; private set; }
}
public class Test2
{
}
internal interface IInterface
{
Test2 Test { get; }
}
The error I get is
'ClassLibrary1.Class1<T>' does not implement interface member 'ClassLibrary1.IInterface.Test'.
'ClassLibrary1.Class1<T>.Test' cannot implement 'ClassLibrary1.IInterface.Test' because it does not have the matching return type of 'ClassLibrary1.Test2'.
For more corrective, implement interface explicitly:
public class Class1<T> : IInterface
where T : Test2
{
public T Test { get; private set; }
Test2 IInterface.Test
{
get { ... }
}
}
Then you can avoid compiled error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With