O'Reilly logo

VB.NET Language in a Nutshell, Second Edition by Steven Roman PhD, Paul Lomax, Ron Petrusha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Comparison Operators

There are three main comparison operators: < (less than), > (greater than), and = (equal to). They can be used individually, or any two operators can be combined with each other. Their general syntax is:

result = expression1 <operator> expression2

The resulting expression is True (-1), False (0), or Null. A Null results if and only if either expression1 or expression2 itself is Null.

What follows is a list of all the comparison operators supported by VB.NET, as well as an explanation of the condition required for the comparison to result in True:

>

expression1 is greater than and not equal to expression2.

<

expression1 is less than and not equal to expression2.

<>

expression1 is not equal to expression2 (less than or greater than).

>=

expression1 is greater than or equal to expression2.

<=

expression1 is less than or equal to expression2.

=

expression1 is equal to expression2.

Comparison operators can be used with both numeric and string variables. However, if one expression is numeric and the other is a string, the numeric expression will always be “less than” the string expression. If both expression1 and expression2 are strings, the “greatest” string is the one that is the longest. If the strings are of equal length, the comparison is based on the value of the Option Compare setting. If its value is Binary, the comparison is case sensitive. (Lowercase letters are “greater” than their uppercase counterparts.) If its value is Text, the comparison is not ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required