Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Visual Studio
Reference
 Operators Compared in Different Lan...
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
Visual Studio
Operators Compared in Different Languages

Updated: August 2008

This topic lists the operators for Visual Basic, C++, C#, JScript, and Visual FoxPro.

For details about operators in this language

See

Visual Basic

Operators Summary

C++

C++ Operators

User-Defined Operators

C#

C# Operators

JScript

JScript Operators

 

Visual Basic

C++

C#

JScript

Visual FoxPro

Additive

 

 

 

 

 

  Addition

+

+

+

+

+

  Subtraction

-

-

-

-

-

Multiplicative

 

 

 

 

 

  Multiplication

*

*

*

*

*

  Division

/

/

/

/

/

  Integer division

\

/1

/1

 

 

  Modulus division (returning only the remainder)

Mod (also works with floating point)

%

%

% (also works with floating point)

%

Mod

  Exponentiation

^

n/a

n/a

n/a

^ **

Assignment

 

 

 

 

 

  Assignment

=

=

=

=

=

  Addition

+=

+=

+=

+=

+

  Subtraction

-=

-=

-=

-=

-

  Multiplication

*=

*=

*=

*=

*

  Division

/=

/=

/=

/=

/

  Integer division

\=

n/a

/=1

n/a

n/a

  Exponentiation

^=

n/a

n/a

n/a

n/a

  String concatenation

&=

+=

+=

+=

+

-

$

  Modulus division

n/a

%=

%=

%=

%

  Left shift

<<=

<<=

<<=

<<=

BITLSHIFT( )

  Right shift

>>=

>>=

>>=

>>=

BITRSHIFT( )

  Bitwise AND

n/a

&=

&=

&=

BITAND( )

  Bitwise exclusive OR

n/a

^=

^=

^=

BITXOR( )

  Bitwise inclusive OR

n/a

|=

|=

|=

BITOR( )

  Null coalescing

If( )

n/a

??

n/a

n/a

Relational and equality

 

 

 

 

 

  Less than

<

<

<

<

<

  Less than or equal to

<=

<=

<=

<=

<=

  Greater than

>

>

>

>

>

  Greater than or equal to

>=

>=

>=

>=

>=

  Equal

=

==

==

==

=

  Not equal

<>

!=

!=

!=

<>

#

!=

  Reference variable comparison

Is

IsNot

n/a

==

==

COMPOBJ( )

  Reference type comparison

TypeOf x Is Class1

n/a

x is Class1 (also see as and typeof)

instanceof

n/a

  String comparison

=

Equals

(There are functions to compare and concatenate strings)

==

Equals

==

=

  CString concatenation

&

n/a

+

+

+

  Short circuited Boolean AND

AndAlso

&&

&&

&&

AND

.AND.

  Short circuited Boolean OR

OrElse

||

||

||

n/a

Bit shift

 

 

 

 

 

  Left shift

<<

<<

<<

<<

n/a

  Right shift

>>

>>

>>

>>

>>>

n/a

Scope resolution

 

 

 

 

 

  Scope resolution

.

MyBase

MyClass

::

.

base

n/a

::

Postfix2

 

 

 

 

 

  Array element

( )

[ ]

[ ]

[ ]

[ ]

( )

  Function call

( )

( )

( )

( )

( )

  Type cast or conversion

CInt

CDbl

...

CType

(type)

(type)

type( )

n/a

  Member selection

.

!

.

->

.

.

.

  Postfix increment

n/a

++

++

++

n/a

  Postfix decrement

n/a

--

--

--

n/a

Unary3

 

 

 

 

 

  Indirection

n/a

*

* (unsafe mode only)

n/a

n/a

  Address of

AddressOf

&

& (unsafe mode only; also see fixed)

n/a

n/a

  Logical NOT

Not

!

!

!

!

NOT

.NOT.

  One's complement

Not

~

~

~

BITNOT( )

  Prefix increment

n/a

++

++

++

n/a

  Prefix decrement

n/a

--

--

--

n/a

  Size of type

n/a

sizeof

sizeof

n/a

n/a

  Comma

n/a

,

n/a

,

n/a

Bitwise

 

 

 

 

 

  Bitwise AND

And

&

&

&

BITAND( )

  Bitwise exclusive OR

Xor

^

^

^

BITXOR( )

  Bitwise inclusive OR

Or

|

|

|

BITOR( )

Logical

 

 

 

 

 

  Logical AND

And

&

&

&&

AND

.AND.

  Logical OR

Or

|

|

||

OR

.OR.

Conditional

 

 

 

 

 

  Ternary conditional

If( )

?:

?:

?:

n/a

Pointer to member

 

 

 

 

 

  Pointer to member

n/a

.* ->

. (Unsafe mode only)

n/a

n/a

Reference

 

 

 

 

 

  Reference

n/a

&

n/a (use reference types)

n/a

@

1. The division operator is overloaded to handle both integer and floating-point division, depending on the operands.

2. Postfix operators have the highest order of precedence in expression evaluation.

3. Unary operators appear before the operand and associate from right to left.

Date

History

Reason

August 2008

Updated references to If operator, ^=, and string equality operator in Visual Basic.

Customer feedback.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
+ and += string concatenation operators in VB      kleinma   |   Edit   |   Show History
the operators + and += are valid VB syntax for concatenating strings. They work the same way as & and &= do.
Flag as ContentBug
Several corrections to article      Kathleen Dollard ... Thomas Lee   |   Edit   |   Show History
1) Visual Basic has a null coalescing operator starting with VB 9.0. This is NOT the old IIF function but a true coalescing operator.

Dim x = If(y, "Fred")

2) Visual Basic has an exponentiation assignment operator that is missing from this list ^=

3) The equals and not equals sign work perfectly well for strings in Visual Basic (as well as C#). You may chose to use StringComp from the Visual Basic library, but that would be unusual and it is NOT an operator. When comparisons need to be locale aware, Equals works well, and for other relationships, the System.String.Compare and CompareOrdinal work well.

4) Logical operators for VB should include AndAlso and OrElse. When used with booleans, And and Or are boolean operators, so their inclusion is correct. And and Or are Bitwise operators when used with integers (at a bit level these are the same thing - flipping bits). AndAlso and OrElse are only used with booleans and always short circuit.

5) The inclusion of IIF as a ternary operator should be removed from this list. It is outdated, and not an operator. It evaluates all arguments, which makes it basically useless. The parallel to C#'s ?: operator is If starting with VB 9.0.I have no clue what a binary conditional is supposed to mean. When used with two arguments, If is a null coalescing operator per my item #1

MS docs have said they will review and update this item.
Really true coalescing?      Christian Jacob   |   Edit   |   Show History
If Dim x = If(y, String.Empty) really is NOT the old IIF function, then why does the Reflector code show up an IIF function then?

x = IIf((NotVB$LW$t_string$S0IsNothing), VB$LW$t_string$S0, String.Empty)

Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker