vb.net - 对接口(interface)继承感到困惑

标签 vb.net interface

我知道我应该更广泛地使用它,但我们的代码只有少数接口(interface),所以我对它们有点菜鸟。这是我的问题。在文件一中我有这个:

Friend Interface IDateRow
    Property Name() As String
    ...
End Interface
Friend Interface IAmountRow
    Property StartDate() As IDateRow
    Property EndDate() As IDateRow
    ...
End Interface

在文件 2 中我有这个:

Friend Class DateRow
    Inherits DtaRow
    Implements IDateRow
    Friend Property Name() As String Implements IDateRow.Name
    ...
End Class

到目前为止一切顺利。现在...

Friend Class AmountRow
    Inherits DtaRow
    Implements IAmountRow
    Friend Property StartDate() As DateRow Implements IAmountRow.StartDate

这行不通 - 它说:

'StartDate' cannot implement 'StartDate' because there is no matching property on interface 'IAmountRow'.

我认为这是因为它返回 DateRow 而不是 IDateRow 是否正确? DateRow 实现了 IDateRow,因此它似乎应该是合法的。

我知道我在这里错过了一些愚蠢的东西......

最佳答案

您必须使用与接口(interface)完全相同的类型来实现属性 - 所以

Friend Property StartDate() As DateRow Implements IAmountRow.StartDate

应该是

Friend Property StartDate() As IDateRow Implements IAmountRow.StartDate

关于vb.net - 对接口(interface)继承感到困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53216622/

相关文章:

vb.net - 对于每个循环迭代计数

vb.net - 序列化包含对象列表的对象

c# - VB.net 界面无法编译,为什么?

c# - 使用 ExeCOMServer 时无法将类型为 '...' 的 COM 对象转换为接口(interface)类型 '...'

Java RESTful Web 服务 - 注释接口(interface)而不是类

mysql - Vb.net 和 MySQL 问题

c# - 检测串口电压

.net - 获取VB.NET中的程序路径?

c# - 如何在注入(inject)的类上调用泛型方法而不通知泛型类型的父类?

c# - 要求接口(interface)实现具有静态 Parse 方法