我知道我应该更广泛地使用它,但我们的代码只有少数接口(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/