Error that I must implement a function in a class even though function is defined [duplicate]

三世轮回 提交于 2019-12-05 09:41:27

Unlike in c#, where the name of the method just has to match the one in the interface, in VB.NET, all interface implementations must always be explicitly stated with Implements keywords on each member:

Protected Class QueryParameterComparer
    Implements IComparer(Of QueryParameter)

    Public Function Compare(x As QueryParameter, y As QueryParameter) As Integer Implements IComparer(Of QueryParameter).Compare
        ' ...
    End Function
End Class

VB.Net requires you to specify which methods are the implementation methods of your interfaces.

Public Function Compare(x As QueryParameter, y As QueryParameter) As Integer Implements System.Collections.Generic.IComparer(Of QueryParameter).Compare

It's odd, but it does allow for you to specify a different function name for the implementation. This makes it so that a direct access to your class can have one name for the function, but a reference through the interface would have the interface method name. Something else you can do is specify the method a Private so that you can only access the method through an interface reference.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!