Is it possible to define an interface in C # that has a default implementation? (so that we can define a class that implements this interface without implementing this particular default method).
I know extension methods (as described in this link ). But this is not my answer, because having a method extension similar to the following, the compiler still complains about the implementation of MyMethod in MyClass:
public interface IMyInterface { string MyMethod(); } public static class IMyInterfaceExtens { public static string MyMethod(this IMyInterface someObj) { return "Default method!"; } } public class MyClass: IMyInterface {
I ask about this because (at least as far as I understand) this can be done in Java (see here ).
PS: with an abstract base class with some method, not my answer is also simply because we do not have multiple inheritance in C #, and it differs from the default for interfaces (if possible!).
source share