我创建了一个自定义 ValueType:
Private Structure MyValueType
Private _integerValue As Integer
Public Sub New(initValue As Integer)
_integerValue = initValue
End Sub
Public Overrides Function ToString() As String
Return _integerValue.ToString
End Function
End Structure
但我不知道如何测试这样的值:
Dim v As New MyValueType(3)
Dim x As New MyValueType(4)
If v = x Then 'fails compile
MessageBox.Show("The values are the same")
End If
错误:
Operator '=' is not defined for Types MyValueType and MyValueType
那么如何为我的 ValueType 定义运算符(我知道这一定很简单,但我在任何地方都找不到示例!)?
注意我不想测试If v.Equals(x)