Consider the following interface:
public interface IFoo { M Bar<M>(); }
Trying to implement this with
class Foo : IFoo { public M Bar<M>() { return new M(); } }
does not work, the compiler complains that in M no restriction new() .
When I add a restriction, as in
class Foo : IFoo { public M Bar<M>() where M : new() { return new M(); } }
this still does not do the trick, since the restrictions of Foo.Bar now do not comply with the restrictions of the interface method (and I cannot change them).
Documentation for compiler error CS0425 reports
To avoid this error, make sure the where clause is identical in both declarations or implement the interface explicitly.
If “implementing the interface explicitly” is the solution: how to do it?
source share