C# 默认接口实现 - 无法覆盖

C# default interface implementation - can't override

我正在按照本指南 https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-8.0/default-interface-methods 使用默认接口实现功能。我复制了一段代码,该代码在接口 IA 中定义了默认实现,然后在接口 IB:

中覆盖了它
interface I0
{
    void M() { Console.WriteLine("I0"); }
}

interface I1 : I0
{
    override void M() { Console.WriteLine("I1"); }
}

但它给出了错误 CS0106 The modifier 'override' is not valid for this item 和警告 CS0108 'I1.M()' hides inherited member 'I0.M()'. Use the new keyword if hiding was intendedTargetFramework 设置为 net5.0LangVersionlatest。为什么即使在官方文档中描述它也不起作用?

text 中它说“不允许隐式覆盖”。

令人困惑的是,它后面的 IC 接口没有重复该语句,在使用隐式方法时,使其看起来像隐式方法有效IC 似乎是你从中复制的界面。

显然,带有 override 关键字的示例不正确,必须删除该关键字。此外,它仅在显式指定方法接口时才有效:

interface I0
{
    void M() { Console.WriteLine("I0"); }
}

interface I1 : I0
{
    void I0.M() { Console.WriteLine("I1"); }
}