[英]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.