NCalc mathematical expression in C# -

2.5k Views Asked by At

I'm using NCalc to create Mathematical expression in C#:

       Expression e = new Expression("2 + 3 * 5");

        Debug.Assert(17 == e.Evaluate());

But second line gives me an error - "Operator == cannot be applied to operands of type int and object"

How to solve this problem?

1

There are 1 best solutions below

1
On

The Evaluate() method returns an object (from the source code), so you need to insert a cast to make this work:

Debug.Assert(17 == (int) e.Evaluate());

The "simple expressions" example on the NCalc home page is incorrect.