Values
A value is a terminal token representing a concrete element. This can be:
- An int
- Any floating point number, like double
- A DateTime or TimeSpan
- A bool
- A string
- A char
- A Function
- An Identifier (parameter)
- A LogicalExpressionList (List of other expressions)
Integers
They are represented using numbers.
123456
They are evaluated as int. If the value is too big, it will be evaluated as long.
Floating point numbers
Use the dot to define the decimal part.
123.456
.123
They are evaluated as double, unless you use DecimalAsDefault.
Scientific notation
You can use the e to define power of ten (10^).
1.22e1
1e2
1e+2
1e+2
1e-2
.1e-2
1e10
They are evaluated as double, unless you use DecimalAsDefault.
DateTime
Must be enclosed between sharps.
#2008/01/31# // for en-US culture
#08/08/2001 09:30:00#
NCalc uses the current Culture to evaluate them.
TimeSpan
Must be enclosed between sharps.
#20:42:00#
Booleans
Booleans can be either true
or false
.
true
Strings
Any character between single or double quotes are evaluated as string.
'hello'
greeting("Chers")
You can escape special characters using \, ', \n, \r, \t.
Chars
If you use <xref:ExpressionOptions.AllowCharValues>, single quoted strings are interpreted as char
var expression = new Expression("'g'", ExpressionOptions.AllowCharValues);
var result = expression.Evalutate();
Debug.Assert(result); // 'g' -> System.Char
Guid
NCalc also supports Guid, they can be parsed with or without hyphens.
b1548bd5-2556-4d2a-9f47-bb8d421026dd
getUser(78b1941f4e7941c9bef656fad7326538)
Function
A function is made of a name followed by braces, containing optionally any value as arguments.
Abs(1)
doSomething(1, 'dummy')
Please read the functions page for details.
Parameters
A parameter as a name, and can be optionally contained inside brackets or double quotes.
2 + x, 2 + [x]
Please read the parameters page for details.
Lists
Lists are collections of expressions enclosed in parentheses. They are the equivalent of List<LogicalExpression>
at CLR.
('Chers', secretOperation(), 3.14)