11得票2回答
默认接口方法和自动属性的默认值

鉴于自动属性编译为get_method、set_method和私有变量,而C# 8引入了默认接口方法 接口中的属性可以有默认实现吗? 特别是只读属性?

10得票2回答
C# 8中的默认接口方法

考虑以下代码示例: public interface IPlayer { int Attack(int amount); } public interface IPowerPlayer: IPlayer { int IPlayer.Attack(int amount) { ...

10得票1回答
C#8接口默认值:如何以良好且可用的方式实现默认属性

我非常喜欢C#8中接口默认实现的想法。但是在尝试后,我感到非常失望... 这里有一个简单的例子,我已经在C#8 interfaces with properties/methods defined in them - apparently not working中找到了其中一部分答案,解释了...

10得票2回答
当使用接口的委托作为参数类型时,逆变无效。

考虑具有委托的逆变接口定义:public interface IInterface<in TInput> { delegate int Foo(int x); void Bar(TInput input); void Baz(TInput...

10得票1回答
如何调用默认方法而非具体实现

C# 8为什么改变了默认接口方法的行为? 在以前(当默认接口方法未发布时)以下代码:interface IDefaultInterfaceMethod { // By default, this method will be virtual, and the virtual keywo...

9得票5回答
C#接口中与Java 8默认方法等效的方法

我听说Java 8提供了在接口中定义函数的灵活性。我认为,我们可以利用这个特性,在实现这种接口的所有类中都有一些默认状态。 那么我的问题是,C#目前是否也有这样的功能?微软在这方面有什么计划吗?

8得票3回答
当我在从接口派生的类中调用一个具有默认实现的接口时,为什么需要将'this'转换为接口类型?(问题涉及C# 8.0)

我有一个使用C# 8和.NET Core 3.1编写的简单控制台程序: using System; namespace ConsoleApp34 { public interface ITest { public void test() {...

7得票2回答
如果在C# 8.0中实现了默认接口方法,那么我为什么还需要抽象类?

我最近看到了一份关于下一版本C#中正在考虑添加的功能列表,其中之一被称为“默认接口方法”: 简而言之,它将允许您在接口本身上定义实际的方法实现,这意味着接口现在可以有实现。既然如此,并且C#类可以实现/继承多个接口,那么我为什么还要使用抽象类呢? 我能想到的唯一一件事是接口无法拥有构造函数...

7得票1回答
C#-8接口中的抽象、虚拟和密封方法

以下接口在使用C#-8.0的.Net Core控制台应用程序中没有错误 interface I { public abstract void f(); public virtual void g() => Console.WriteLine("g"); publ...