Let\'s say I have such interface and concrete implementation
public interface IMyInterface
{
T My();
}
public class MyConcrete : IMyInterface&l
Your solution does not work for two reasons.
First, an interface is a contract. When you implement IMyInterface2
you guarantee that you will implement a function named My
that takes a generic type parameter and returns that type. MyConcrete2
does not do this.
Second, C# generics do not allow any kind of type parameter specialization. (I do wish C# supported this.) This is a common thing in C++ templates where your example would compile, but any usages of MyConcrete2
would fail to compile if they don't call My
with a string
.