1

Consider the following interface, with a default implementation of TestMethod

public interface TestInterface
{
    public int TestMethod()
    {
        return 15;
    }
}

Calling TestMethod in the following class will cause a StackOverflowException:

public class TestClass : TestInterface
{
    public int TestMethod()
    {
        return 1 + (this as TestInterface).TestMethod();
    }
}

Now I understand why this is, but is there any way to get around it? Something like base.TestMethod() for referencing one of the class's implemented interfaces?

I know I could rename the method in TestInterface and reference it in TestClass that way, but that would cause problems for other classes that don't need to reference the default implementation.

  • 2
    See https://stackoverflow.com/questions/59398027/c-sharp-8-base-interfaces-default-method-invocation-workaround – Hank Nov 22 '21 at 18:22

1 Answers1

-1

you need to use "public override" to do what you are asking.

Sye
  • 17
  • 5