我有一个通用接口,即使我在实现它时声明了类型,它也说实现的类错过了成员的所有实现。
界面
Interface IBuilder(Of T)
Function Number(ByVal literal As String) As T
End Interface
实施
Class BracketsBuilder
Implements IBuilder(Of String)
Public Function Number(number__1 As String) As String
Return number__1
End Function
End Class
当我尝试运行代码时,我得到
类"括号生成器"必须实现"函数编号(文字为 字符串)作为接口"IBuilder(Of String)"的字符串"。
您需要在 Number 函数的声明上指明它是接口中定义的 Number 函数的实现
Interface IBuilder(Of T)
Function Number(ByVal literal As String) As T
End Interface
Class BracketsBuilder
Implements IBuilder(Of String)
Public Function Number(number__1 As String) As String Implements IBuilder(Of String).Number
Return number__1
End Function
End Class
如果您键入
Class BracketsBuilder
Implements IBuilder(Of String)
然后按回车键,Visual Studio将为您添加函数声明。