通用接口缺少实现

时间:2015-06-15 23:03:18

标签: vb.net interface implements generic-interface

我有一个通用接口,即使我在实现它时声明了类型,它说实现的类错过了所有成员的实现。

界面

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

当我尝试运行代码时,我得到了

  

Class' BracketsBuilder '必须实现' 功能编号(字面值为   字符串)作为字符串' for interface' IBuilder (Of String)'。

1 个答案:

答案 0 :(得分:3)

您需要在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)

然后按Enter键,Visual Studio将为您添加Function声明。