Operators
There are a large number of operators in C#.
link - learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/
| Operator | C# | VB.Net |
| Compare object reference type | x is Class1 | TypeOf x Is Class1 |
| Assignment | = | = |
| Concatenation | + | & |
| Concatenation Self Assignment | += | &= |
| Equality | == | Is |
| Equality - Not equal | != | <> |
| Logical AND | & | And |
| Logical AND Self Assignment | &= | |
| Logical AND Conditional | && | AndAlso |
| Logical OR | | | Or |
| Logical OR Self Assignment | |= | |
| Logical OR Conditional | || | OrElse |
| Logical OR Exclusive | ^ | Xor |
| Logical OR Exclusive Self Assignment | ^= | |
| Logical NOT | ~ | Not |
| Logical NOT / unary ?? | ! | Not |
| Division (integer) | / (depending on the operands) | \ ?? |
| Division Assignment (integer) | /= (depending on the operands) | \= ?? They are opposite directions ?? |
| Multiplication | * | * |
| Multiplication Self Assignment | *= | *= |
| Subtraction | - | - |
| Subtraction Self Assignment | -= | -= |
| Addition | + | + |
| Addition Self Assignment | += | += |
| Modulus | % | % |
| Modulus (division returning only the remainder) | % (eg 10 % 5) | Mod (eg 10 Mod 5) |
| Modulus Self Assignment | %= | |
| Exponentiation | n/a | ^ |
| Bitwise AND | &= | |
| Bitwise OR | ||
| Address of | & (unsafe mode only) | AddressOf |
| Type cast | (type) | CInt, CDbl, .. , CType |
| Pointer to member | . (Unsafe mode only) | |
| Scope resolution | ., base | . |
| Conditional | ?: (right to left) | IIf |
| One's complement / unary ?? | ~ | Not |
| Indirection | * (unsafe mode only) | |
| unary plus | + | |
| Postfix increment | ++ | |
| Postfix decrement | ||
| Left Shift | << | |
| Left Shift Self Assignment | <<= | |
| Right Shift | >> | |
| Right Shift Self Assignment | >>= | |
| Size of type | sizeof |
Primary
Unary
++variable
--variable
Multiplication
value1 * value2
value1 / value2
value1 % value2
Addition
value1 + value2
value1 - value2
Shift
Logical
It is common to want to test whether two conditions are both true or only one is true or neither is true.
AND
if (oMyObject = null) & (bUpdate == false)
{
}
The second condition is only checked if the first one is true. This is often referred to as short circuiting.
if (oMyObject = null) && (bUpdate == false)
{
}
OR
if (oMyObject = null) | (sFullName == "Steven")
{
}
The second expression is only evaluated if the first expression is true. This is often referred to as short-circuit evaluation.
if (oMyObject = null) || (sFullName == "Steven")
{
}
Exclusive OR
Exclusive Or. True if only one statement is true.
if (oMyObject = null) ^ (sFullName == "Steven")
{
}
Relational and Type Testing
Assignment
Lambda
.NET Library > Framework 3.5 > Lambda Expressions
Operator Precedence
The following is a list of the types of operators in order of precedence
| Order | Symbol | Operator |
| 1 | ^ | |
| 2 | - |
Primary
Unary
Multiplication
Addition
Shift
Relational and Type Testing
Equality
Self Assignment
Logical
Conditional
Assignment
Lambda
Equality
Are the variables (or objects) equal.
Operator - ==
Can be used to compare both value and reference data types.
For value types this returns true if the values are equal
For the string reference type this compares the contents.
For all other reference types this compares the identity on the heap.
if (svalue1 == svalue2)
{
}
'VB.Net Equivalent
If (svalue1 = svalue2) Then
End If
Operators - !=
Are the variables different
if (ovalue1 != null)
{
}
'VB.Net Equivalent
If ( Not (ovalue Is Nothing) ) Then
End If
If (ovalue IsNot Nothing) Then
End If
Equals() Method
Can be used to compare both value and reference data types.
For all types this compares the contents (not the identity on the heap)
Also known as testing for equality without coalescing.
If (svalue1.Equals(svalue2))
{
}
You should always use the Equals() method to check reference types for equality
© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext