我創建了一個自定義的值類型:不能設置「值」的自定義的值類型
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
那麼,如何定義我的值類型(我知道這一定是簡單的,但我找不到任何地方
的一個實例!)操作符?
注意我不想考沿着以下(你需要重載=
和<>
運營商都)線If v.Equals(x)
[Visual Basic 2005中的運算符重載](http://msdn.microsoft.com/zh-cn/library/ms379613(v = vs .80).aspx) – Oded