加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

vb.net – 即使定义了函数,我必须在类中实现一个函数的错误

发布时间:2020-12-17 00:01:37 所属栏目:大数据 来源:网络整理
导读:参见英文答案 Class ‘QueryParameterComparer’ must implement Function Compare.2个 我得到错误:类’QueryParameterComparer’必须为接口’System.Collections.Generic.IComparer(Of QueryParameter)’实现’Function Compare(x As QueryParameter,y As
参见英文答案 > Class ‘QueryParameterComparer’ must implement Function Compare.2个
我得到错误:类’QueryParameterComparer’必须为接口’System.Collections.Generic.IComparer(Of QueryParameter)’实现’Function Compare(x As QueryParameter,y As QueryParameter)As Integer’.

在这个类定义上:

Protected Class QueryParameterComparer
        Implements IComparer(Of QueryParameter)

        Public Function Compare(x As QueryParameter,y As QueryParameter) As Integer
            If x.Name = y.Name Then
                Return String.Compare(x.Value,y.Value)
            Else
                Return String.Compare(x.Name,y.Name)
            End If
        End Function

    End Class

我也尝试过完全写出来:

Protected Class QueryParameterComparer
        Implements System.Collections.Generic.IComparer(Of QueryParameter)

        Public Function Compare(x As QueryParameter,y.Name)
            End If
        End Function

    End Class

我错过了什么?

与c#不同,其中方法的名称必须与接口中的名称相匹配,在VB.NET中,必须始终使用每个成员上的Implements关键字明确声明所有接口实现:
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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读