VB.Net program to overload the logical ‘Xor’ operator
'VB.net program to overload the logical "Xor" operator.
Class Sample
Dim val As Boolean
Sub SetValue(ByVal v As Boolean)
val = v
End Sub
Public Shared Operator And(ByVal S1 As Sample, ByVal S2 As Sample) As Boolean
Dim result As Boolean
result = (S1.val = True Xor S2.val = True)
Return result
End Operator
End Class
Module Module1
Sub Main()
Dim obj1 As New Sample()
Dim obj2 As New Sample()
obj1.SetValue(True)
obj2.SetValue(True)
If (obj1 And obj2) Then
Console.WriteLine("True")
Else
Console.WriteLine("False")
End If
obj1.SetValue(False)
obj2.SetValue(True)
If (obj1 And obj2) Then
Console.WriteLine("True")
Else
Console.WriteLine("False")
End If
End Sub
End Module
False
True
Press any key to continue . . .
Table of Contents