Mark Lalor Mark Lalor - 1 year ago 136
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...?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download