Operators

Expressions consist of operands and operators. Expression operators indicate, which actions to apply to the operands. Examples of operators are summation, subtraction, and so on. Examples of operands are literals, fields, local variables, and expressions.

There are three types of operators:

The order of calculating operators in an expression is determined by the precedence and associativity of the operators. Operands in an expression are calculated from left to right.

Operator Precedence and Associativity

When an expression contains multiple operators, the precedence of the operations controls, in which order individual operators are calculated. For example, the expression x + y * z is calculated as x + (y * z) because the multiplication operator has higher priority than the summation operator. Operator priority is established by defining corresponding grammar rules. The following table contains all operators in order of precedence from highest to lowest:

Operator category Operators
Basic x.y  F(x)  a[x]  New
Unary +  -  Not
Multiplicative *  /  Div Mod
Additive +  -
Type comparison and testing <  >  <=  >=  Is  As
Equality =  <>
Logical AND And
Logical OR Or  Xor
Selection operator ?:

When an operand occurs between two operations with the same precedence, the associativity of the operators controls, in which order operators are executed:

Operator precedence and associativity can be controlled using parentheses.

See also:

Expressions