Operators in Visual Basic .NET

In this article, I will explain you about Operators in Visual Basic .NET
  • 6956

Operators

Visual Basic .NET comes with plenty built-in operators, which let you manipulate your data. An operators can perform action on one or more operands.

Arithmetic Operators

When we want to perform arithmetic operation like any numeric calculation then we use Arithmetic Operators. List of  Arithmetic Operators is given below:

Operator

Use

+

Addition

-

Subtraction

*

Multiplication

/

Division

\

Integer Division

-

Negation

^

Exponentiation

Mod

Modulus Arithmetic


Example:


Imports System.Console
Module Module1
 
    Sub Main()
        Dim A, B, C As Integer
        A = 60
        B = 40
        C = A + B
        WriteLine("Addition of Integer" & " = " & C)
        C = A - B
        WriteLine("Subtraction of Integer" & " = " & C)
        C = A * B
        WriteLine("Multiplication of Integer" & " = " & C)
        C = A / B
        WriteLine("Division of Integer" & " = " & C)
        Read()
    End Sub
 
End Module

Output:

Output1.gif

Concatenation Operators

When we want to join multiple strings into a single string then we use Concatenation Operators. List of  Concatenation Operators is given below:

Operator

Use

&

String Concatenation

+

String Concatenation


Example:

Imports System.Console
Module Module1
 
    Sub Main()
        Dim A, B, C As Integer
        A = 60
        B = 40
        C = A + B
        WriteLine("Addition of Integer" & " = " & C)
        C = A - B
        WriteLine("Subtraction of Integer" & " = " & C)
        C = A * B
        WriteLine("Multiplication of Integer" & " = " & C)
        C = A / B
        WriteLine("Division of Integer" & " = " & C)
        Read()
    End 
Sub

End Module

Output:

Output2.gif

Comparison Operators

When we want to compare the operands and on the basis of that comparison we want a logical value then we use Comparison operators. List of  Comparison Operators is given below:

Operator

Use

=

Equality

Less than

Greater than

< =

Less than or equal to

> =

Greater than or equal to

< >

Inequality



Example:

Imports System.Console
Module Module1
 
    Sub Main()
        Dim A, B As Integer
        WriteLine("Enter two values for A and B ")
        A = Val(ReadLine())
        B = Val(ReadLine())
        If A = B Then
            WriteLine("Both are equal ")
        ElseIf A < B Then
            WriteLine("A is less than B ")
        ElseIf A > B Then
            WriteLine("A is greater than B ")
        End If
        Read()
    End Sub
 
End Module

Output:

Output3.gif

Logical / Bitwise Operators

When we want to compare Boolean expressions and want Boolean result then we use Logical Operators. They are the expressions which return a true or false result over a conditional expression. List of  Logical / Bitwise Operators is given below:

Operator

Use

And

Conjunction

Or

Disjunction

Not

Negation

AndAlso

Conjunction

OrElse

Disjunction

Xor

Disjunction


Example:

Imports System.Console
Module Module1
 
    Sub Main()
        Dim B As Boolean
        B = Not 45 > 26
        WriteLine("B is True")
        B = Not 26 > 87
        WriteLine("B is False")
        Read()
    End Sub
 
End Module

Output:

Output4.gif

Summary

I hope this article help you to understand about Operators in Visual Basic .NET 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.