I have created a custom 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
But I can’t work out how I can test the value such as this:
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
Error:
Operator '=' is not defined for Types MyValueType and MyValueType
So how do I define Operators for my ValueType (I know this must be simple but I can’t find an exmaple anywhere!)?
Note I don’t want to test If v.Equals(x)
Something along the lines of the following (you’ll need to overload both the
=and<>operators):