[英]C# How to reference default interface implementation in implementer class
考虑以下接口,默认实现TestMethod
public interface TestInterface
{
public int TestMethod()
{
return 15;
}
}
在下面的 class 中调用TestMethod
会导致 StackOverflowException:
public class TestClass : TestInterface
{
public int TestMethod()
{
return 1 + (this as TestInterface).TestMethod();
}
}
现在我明白为什么会这样了,但是有什么办法可以绕过它吗? 类似base.TestMethod()
的东西用于引用类的实现接口之一?
我知道我可以重命名 TestInterface 中的方法并以这种方式在 TestClass 中引用它,但这会导致其他不需要引用默认实现的类出现问题。
您需要使用“公共覆盖”来执行您的要求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.