user2262230
user2262230

Reputation: 199

NCalc mathematical expression in C# -

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?

Upvotes: 1

Views: 2661

Answers (1)

adrianbanks
adrianbanks

Reputation: 82944

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.

Upvotes: 2

Related Questions