【问题标题】:C# how to add a default implementation to an interface which is overriding another interfaceC#如何将默认实现添加到覆盖另一个接口的接口
【发布时间】:2021-05-25 00:21:23
【问题描述】:

例如:

interface IDottable : IGetDottable
{
    bool try_dot_operator(string name);
    // ... more methods
    IDottable Dottable => this;
}
interface IGetDottable
{
    IDottable Dottable {get;}
}

它给了我:

"'IDottable.Dottable' hides inherited member 'IGetDottable.Dottable'. Use the new keyword if hiding was intended.".

【问题讨论】:

    标签: c# interface c#-8.0 default-implementation


    【解决方案1】:

    试试这个:

    interface IDottable : IGetDottable
    {
         bool try_dot_operator(string name);
         // ... more methods
         IDottable IGetDottable.Dottable => this;
    }
    interface IGetDottable
    {
        IDottable Dottable {get;}
    }
    

    接口中的默认实现不会公开方法。

    【讨论】:

      猜你喜欢
      • 2019-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-01
      • 2014-10-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-31
      相关资源
      最近更新 更多