This documentation is archived and is not being maintained.

11.14 Relational Operators

Visual Studio .NET 2003

The relational operators compare values to one other. The comparison operators are =, <>, <, >, <=, and >=. All of the relational operators result in a Boolean value.

The relational operators have the following general meaning:

  • The = operator tests whether the two operands are equal.
  • The <> operator tests whether the two operands are not equal.
  • The < operator tests whether the first operand is less than the second operand.
  • The > operator tests whether the first operand is greater than the second operand.
  • The <= operator tests whether the first operand is less than or equal to the second operand.
  • The >= operator tests whether the first operand is greater than or equal to the second operand.

The relational operators are defined for the following types:

  • Boolean. The operators compare the truth values of the two operands. True is considered to be less than False, which matches with their numeric values.
  • Byte, Short, Integer, and Long. The operators compare the numeric values of the two integral operands.
  • Single and Double. The operators compare the operands according to the rules of the IEEE 754 standard.
  • Decimal. The operators compare the numeric values of the two decimal operands.
  • Date. The operators return the result of comparing the two date/time values.
  • Char. The operators return the result of comparing the two Unicode values.
  • String. The operators return the result of comparing the two values using either a binary comparison or a text comparison. The comparison used is determined by the compilation environment and the Option Compare statement. A binary comparison determines whether the numeric Unicode value of each character in each string is the same. A text comparison does a Unicode text comparison based on the current culture in use on the .NET Framework. When doing a string comparison, a null reference is equivalent to the string literal "".
RelationalOperatorExpression ::=
   Expression = Expression |
   Expression < > Expression |
   Expression < Expression |
   Expression > Expression |
   Expression < = Expression |
   Expression > = Expression

See Also

11.12.1 Operator Precedence and Associativity | 11.12.2 Object Operands | 11.12.3 Operator Resolution | 11.13 Arithmetic Operators | 11.15 Like Operator | 11.16 Concatenation Operator | 11.17 Logical Operators | Comparison Operators (Visual Basic Language Reference) | Comparison Operators (Visual Basic Language Concepts)

Show: