NCalc Operators
Expressions can be combined using operators, each of which has a precedence priority. Below is the list of expression priorities in descending order:
- Primary
- Unary
- Power
- Multiplicative
- Additive
- Relational
- Bitwise
- Logical
Doc editor: The original omits
7. Bitwise.
These operators follow the precedence rules to determine the order in which operations are performed in an expression.
Logical
Logical operators perform logical comparisons between expressions.
or,||and,&&
Examples:
true or false and true
(1 == 1) || falseTheandoperator has higher priority than theoroperator, thus in the example above,false and trueis evaluated first.
Relational
Relational operators compare two values and return a boolean result.
Theinandnot inoperators right value must be a string or IEnumerable.
=,==,!=,<><,<=,>,>=in,not in
Examples:
3 < 2
42 == 42
'Insert' in ('Insert', 'Update')
"Sergio" in "Sergio is at Argentina"
"Mozart" not in ("Chopin", "Beethoven", GetComposer())
945 != 202Additive
Additive operators perform addition and subtraction.
+,-
Examples:
1 + 2 - 3Multiplicative
Multiplicative operators perform multiplication, division, and modulus operations.
*,/,%
Examples:
1 * 2 % 3Bitwise
Bitwise operators perform bitwise operations on integers.
&(bitwise and),|(bitwise or),^(bitwise xor),<<(left shift),>>(right shift)
Examples:
2 >> 3Unary
Unary operators operate on a single operand.
!,not,-,~(bitwise not)
Examples:
not trueExponential
Exponential operators perform exponentiation.
**
Examples:
2 ** 2Primary
Primary operators include grouping of expressions, lists and direct values. Check Ncalc Values for more info.
(,)- values
Examples:
2 * (3 + 2)
("foo","bar", 5)
drop_database()
