Mark Lalor Mark Lalor - 1 month ago 7x
C# Question

Evaluate C# string with math operators

Is there an easy way to evaluate strings like


So that you'd get the int value of 24?

Or is there a lot of work needed to get this done...?


Use Ncalc:

Expression e = new Expression("(4+8)*2");
Debug.Assert(24 == e.Evaluate());

Also, this question had been previously asked and has some interesting answers including Ncalc : c# evaluating string "3*(4+2)" yield int 18