1

因为下面的代码有效。“Net 2.0”并不起作用。“网络4.0”?不添加方法有什么解决办法

Public Shared Operator >(ByVal variante1 As Double, ByVal variante2 As MyClass1) As Boolean
Public Shared Operator <(ByVal variante1 As Double, ByVal variante2 As MyClass1) As Boolean

错误消息:重载解析失败,因为没有可访问的 '>' 对这些参数最具体:'公共共享运算符 >(variante1 As MyClass1,variante2 As MyClass1) As Boolean': Not most specific Public Shared Operator >(left as Double, right as Double) As Boolean': 不是最具体的


Public Class Form1

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

      Dim value1 As New MyClass1
      Dim value2 As Double = 0

      Dim result As Boolean = value2 > value1

    End Sub
End Class

Public Class MyClass1

    Public Shared Operator >(ByVal variante1 As MyClass1, ByVal variante2 As MyClass1) As Boolean
        Return True
    End Operator

    Public Shared Operator <(ByVal variante1 As MyClass1, ByVal variante2 As MyClass1) As Boolean
        Return True
    End Operator

    Public Shared Widening Operator CType(ByVal valor As Double) As MyClass1
        Return New MyClass1(valor)
    End Operator

    Public Shared Widening Operator CType(ByVal valor As MyClass1) As Double
        Return 0
    End Operator

    Public Sub New()
    End Sub

    Public Sub New(valor As Double)
    End Sub

End Class
4

0 回答 0