为什么C#8接口成员的默认实现将报告错误

use*_*194 0 resharper c#-8.0 .net-core-3.0 default-interface-member

为什么接口成员的C#8默认实现会报告错误?

public interface Logger
{
    void Info(string message);
    void Error(string message);
    // C#8 Default implementations of interface
    void Warn(string message)
    {
        // "interface method cannot declare a body" error message
    }
}
Run Code Online (Sandbox Code Playgroud)

.NET Core 3.0的配置如屏幕截图所示。

在此处输入图片说明

sol*_*ish 10

这是一个 Resharper/Rider 错误:https ://youtrack.jetbrains.com/issue/RSRP-474628


AAA*_*ddd 6

The feature is sound and your setup is correct. Also the following works for me, i can compile and run the following in .Net Core 3

class Program
{
   interface IDefaultInterfaceMethod
   {
      void DefaultMethod()
      {
         Console.WriteLine("I am a default method in the interface!");
      }
   }
   static void Main(string[] args)
   {
      Console.WriteLine("Hello World!");
   }
}
Run Code Online (Sandbox Code Playgroud)

Note though, i get your error in the IDE!! yet there was no error in the error window. However, it still compiles and runs so it is not C#8.. Seeing this is a sure-sign something else is the issue

在此处输入图片说明

In Short, this is likely a Resharper problem, when i suspended Resharper the false positive went away