【问题标题】:twitter oauth icomparer errortwitter oauth icomparer 错误
【发布时间】:2010-10-14 03:26:56
【问题描述】:

我正在尝试将此代码从 csharp 转换为 vb。使用免费 csharp 到 vb 转换器的所有孩子,但出现错误。请让知道是否有人以前解决过这个问题。

错误:

类 'QueryParameterComparer' 必须为接口 'System.Collections.Generic.IComparer(Of QueryParameter)' 实现 'Function Compare(x As OAuthBase.QueryParameter, y As OAuthBase.QueryParameter) As Integer'

来自 c#code:

protected class QueryParameterComparer : IComparer<QueryParameter>
    {

        public int Compare(QueryParameter x, QueryParameter y)
        {
            if (x.Name == y.Name)
            {
                return string.Compare(x.Value, y.Value);
            }
            else
            {
                return string.Compare(x.Name, y.Name);
            }
        }

    }

转vb代码

Protected Class QueryParameterComparer
        Implements IComparer(Of QueryParameter)

        #Region "IComparer Members"

        Public Function Compare(ByVal x As QueryParameter, ByVal 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 Region
    End Class

【问题讨论】:

    标签: twitter oauth


    【解决方案1】:

    尝试在每个参数类型前面加上OAuthBase.

    或者使用 OAuth 库,例如 DotNetOpenAuthLinqToTwitter,这样您就不必担心了。 :)

    【讨论】:

    • 我以前做过,但我必须添加到实现 IComparer(Of oAuthBase.QueryParameter)
    【解决方案2】:

    在函数声明的末尾添加这个

    实现 IComparer(Of QueryParameter).Compare

    那么就是:

        Public Function Compare(ByVal x As QueryParameter, ByVal y As QueryParameter) As Integer Implements IComparer(Of QueryParameter).Compare
            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
    

    【讨论】:

      【解决方案3】:
          Public Function Compare(ByVal x As OAuth.QueryParameter, ByVal y As OAuth.QueryParameter) As Integer _
          Implements IComparer(Of QueryParameter).Compare
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-08-16
        • 2014-06-01
        • 2015-11-06
        • 2014-02-11
        • 2012-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多