gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 16:59:37 26 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Class 'QueryParameterComparer' must implement Function Compare.

(2 个回答)


6年前关闭。




我收到错误:Class 'QueryParameterComparer' must implement 'Function Compare(x As QueryParameter, y As QueryParameter) As Integer' for interface 'System.Collections.Generic.IComparer(Of QueryParameter)'.
在这个类定义上:

    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 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

我错过了什么?

最佳答案

与在 c# 中方法的名称必须与接口(interface)中的名称匹配的情况不同,在 VB.NET 中,所有接口(interface)实现必须始终使用 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

关于vb.net - 即使定义了函数,我也必须在类中实现函数的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30328991/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com