Show/Hide Toolbars

XSharp

X# uses the following binary operators:

 

Operator

Example

Meaning

+

x + y

addition

-

x - y

subtraction

*

x * y

multiplication

/

x / y

division. If the operands are integers, the result is an integer truncated toward zero (for example, -7 / 2 is -3).

%

x % y

modulus. If the operands are integers, this returns the remainder of dividing x by y. If q = x / y and r = x % y, then x = q * y + r.

^ or **

x ^ y or x ** y

power of. x ^ y returns x to the power of y

default or ??

x DEFAULT y
x ?? y

When x is not null then x, otherwise y. Can be chained: x DEFAULT y DEFAULT z or x ?? y ?? z



 

Binary operators and XBase types

The following XBase types support binary operators.

 

Type

Operator

Description

ARRAY

none

binary operators are not supported for arrays

DATE

+ and -

You can add and subtract a numeric to a date, which is the equivalent of adding days.
You can subtract a date from a date which will return the number of days between the dates

FLOAT

all

You can perform all binary operations on FLOATs when both operands are numeric. The compiler will automatically insert a conversion from <any numeric type> to FLOAT when the right hand side of the binary operator is not a float

SYMBOL

none

binary operators are not supported for arrays

STRING

+ and -

The + operator will add 2 strings. The - operator will add the RHS to the LHS and move all trailing spaces of the LHS to the end of the resulting string. You can also add STRING values and SYMBOL values. The SYMBOLs will automatically be converted to strings

USUAL

all

You can use all binary operators on USUALs. The code in the runtime will check to see if the 2 sides are "compatible" and will produce a runtime error when the operation is not available.