ARTICLE

Operators in Visual Basic .NET

Posted by Atul Chaudhary Articles | Visual Basic 2010 December 31, 2010
In this article, I will explain you about Operators in Visual Basic .NET
 
Reader Level:

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

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 

Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Nevron Diagram
Become a Sponsor