VB.Net program to overload Not operator

Here, we are going to learn how to overload Not operator in VB.Net?
Submitted by Nidhi, on January 13, 2021

Here, we will overload the Not operator using the operator method, The Not operator change the Boolean value True into False or vice versa.

Program/Source Code:

The source code to overload the Not operator is given below. The given program is compiled and executed successfully.

' program to overload "Not" operator.

Class Sample
    Dim X As Boolean
    Sub SetX(ByVal val As Boolean)
        X = val
    End Sub
    Sub PrintX()
        Console.WriteLine("Value is: {0}", X)
    End Sub

    Public Shared Operator Not(ByVal S As Sample) As Boolean
        Dim temp As Boolean
        temp = Not S.X
        Return temp
    End Operator
End Class

Module Module1
    Sub Main()
        Dim obj As New Sample()
        Dim result As Boolean


        result = Not obj
        Console.WriteLine("Result: {0}", result)


        result = Not obj
        Console.WriteLine("Result: {0}", result)
    End Sub
End Module


Value is: True
Result: False
Value is: False
Result: True
Press any key to continue . . .


In the above program, we created a class Sample that contains two methods SetX() and PrintX() to set and print the value of data members. Here, we also implemented a method to overload the Not operator.

After that, we created a module Module1 that contains the Main() method, the Main() method is the entry point for the program. And, we created an object of Sample class and set the value of data member using SetX() method and then perform use Not operator with the object of Sample class and print the result on the console screen.

VB.Net Basic Programs »



Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.