VB.NET Operators

Arithmetic Operators

OperatorDescriptionExample
+AdditionDim sum = a + b
-SubtractionDim diff = a - b
*MultiplicationDim prod = a * b
/Division (floating‑point)Dim quot = a / b
\Integer divisionDim intQuot = a \ b
ModModulus (remainder)Dim r = a Mod b
^ExponentiationDim p = a ^ b

Comparison Operators

OperatorDescriptionExample
=EqualityIf a = b Then ...
<>InequalityIf a <> b Then ...
<Less thanIf a < b Then ...
>Greater thanIf a > b Then ...
<=Less than or equalIf a <= b Then ...
>=Greater than or equalIf a >= b Then ...
IsReference comparisonIf obj1 Is obj2 Then ...
IsNotReference inequalityIf obj1 IsNot obj2 Then ...

Logical (Boolean) Operators

If A Xor B Then ...
OperatorDescriptionExample
AndLogical AND (no short‑circuit)If A And B Then ...
AndAlsoLogical AND with short‑circuitIf A AndAlso B Then ...
OrLogical OR (no short‑circuit)If A Or B Then ...
OrElseLogical OR with short‑circuitIf A OrElse B Then ...
NotLogical negationIf Not A Then ...
XorExclusive OR

String Concatenation Operator

OperatorDescriptionExample
&String concatenationDim full = firstName & " " & lastName

Assignment Operators

OperatorDescriptionExample
=Simple assignmentDim x = 5
+=Add and assignx += 3 ' x = x + 3
-=Subtract and assignx -= 2 ' x = x - 2
*=Multiply and assignx *= 4 ' x = x * 4
/=Divide and assignx /= 2 ' x = x / 2
\=Integer divide and assignx \= 3 ' x = x \ 3
Mod=Modulus and assignx Mod= 5 ' x = x Mod 5
^=Exponentiate and assignx ^= 2 ' x = x ^ 2
&=Concatenate and assignstr &= "World"

Type‑Conversion Operators

OperatorDescriptionExample
CType(..., Type)Runtime conversionDim s As String = CType(i, String)
DirectCast(..., Type)Compile‑time cast (no conversion)Dim obj As Object = DirectCast(str, Object)
TryCast(..., Type)Safe cast returning Nothing on failureDim btn As Button = TryCast(ctrl, Button)