Skip to content

Operator Equal

Paul Squires edited this page Sep 19, 2026 · 1 revision

Home › Operators › Operator = (Equal)

Operator = (Equal)

Compares two expressions for equality

Syntax

Declare Operator = ( ByRef lhs As Byte, ByRef rhs As Byte ) As Integer
Declare Operator = ( ByRef lhs As UByte, ByRef rhs As UByte ) As Integer
Declare Operator = ( ByRef lhs As Short, ByRef rhs As Short ) As Integer
Declare Operator = ( ByRef lhs As UShort, ByRef rhs As UShort ) As Integer
Declare Operator = ( ByRef lhs As Integer, ByRef rhs As Integer ) As Integer
Declare Operator = ( ByRef lhs As UInteger, ByRef rhs As UInteger ) As Integer
Declare Operator = ( ByRef lhs As LongInt, ByRef rhs As LongInt ) As Integer
Declare Operator = ( ByRef lhs As ULongInt, ByRef rhs As ULongInt ) As Integer

Parameters

  • lhs
  • rhs
  • T

Description

Operator = (Equality) is a binary operator that compares two expressions for equality and returns the result - a boolean value mainly in the form of an Integer: negative one (-1) for true and zero (0) for false. Only if the left and right-hand side types are both Boolean, the return type is also Boolean. The arguments are not modified in any way.

This operator can be overloaded to accept user-defined types as well.

Operator = (Equality) should not be confused with initializations or assignments, both of which also use the "=" symbol.

Return Value

Returns negative one (-1) if expressions are equal, or zero (0) if unequal.

Remarks

Usage

result = lhs = rhs

Dialect Differences

  • In the -lang qb dialect, this operator cannot be overloaded.

Differences from QB

  • none

See also

Examples

Dim i As Integer = 0    '' initialization: initialise i with a value of 0

i = 420                 '' assignment: assign to i the value of 420

If (i = 69) Then        '' equation: compare the equality of the value of i and 69

    Print "serious error: i should equal 420"

    End -1

End If

Operator <> (Inequality) is complement to Operator = (Equality), and is functionally identical when combined with Operator Not (Bit-wise Complement).

If (420 = 420) Then Print "(420 = 420) is true."

   If Not (69 <> 69) Then Print "not (69 <> 69) is true."

Category: Operators
Kind: operator


Reproduced from the FreeBASIC Wiki Manual under the GNU Free Documentation License 1.3 — with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. Copyright © the FreeBASIC project and wiki contributors. See License.

Clone this wiki locally