c# - 无法使用接口(interface)默认方法

标签 c# interface c#-8.0 visual-studio-2019

我已经安装了新版本的 Visual Studio 并将项目设置为 C# 8。当我尝试使用如下所示的新界面功能时,它说我无法在界面中实现,这似乎不知何故我无法使用新功能。谁能解释一下为什么,它仍然没有包含在 2019 年预览中吗?

interface IDefaultInterfaceMethod
{
    public void DefaultMethod()
    {
        Console.WriteLine("I am a default method in the interface!");
    }
}

最佳答案

基于this :

Microsoft has fleshed out more details about C# Version 8.0, the next planned major release of the language. C# 8.0 is expected to arrive in 2019, concurrent with the arrival of .Net Core 3.0.

所有 C# 8 功能仍处于开发早期,可能会发生变化。因此,最好等到这些功能最终发布。以下博客也可能有所帮助:

Any estimation for C# 8.0 release date?

并非所有 C# 8.0 功能均可用(Visual Studio 2019 预览版 1)。您可以在以下链接中找到当前可用功能的列表:

Take C# 8.0 for a spin

关于c# - 无法使用接口(interface)默认方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53694961/

相关文章:

c# - vs2019.9.2 对 undefined variable 使用属性模式时引发运行时错误并编译失败,这是预期的编译错误

c# - 在按钮/链接点击上调用 javascript 和 C#

c# - ConfigureAwait(false) 与 ADO.Net SQLConnection 对象

c# - 如何在 C# 中的每个数学函数前面避免 "Math."?

c# - 来自外部项目的引用接口(interface)

java - 具有 future 兼容性且不会破坏 future 修改的类

c# - (byte)Convert.ToChar(anyStringOfLengthOne) 怎么可能抛出错误?

delphi - 枚举实现给定接口(interface)的所有 Delphi 类?

c# - EF Core 3.0 可为空的导航属性

c# - C#8“默认”是什么?对泛型类型做什么?