Q:

How can I parse math operator from string in c#

I've a dropdown like this
                    @Html.DropDownList("Operator", new List<SelectListItem>
                {
                    new SelectListItem() {Text = "/", Value = "/", Selected = true},
                    new SelectListItem() {Text = "*", Value = "*"},
                    new SelectListItem() {Text = "+", Value = "+"},
                    new SelectListItem() {Text = "-", Value = "-"}
                }, new {@Class = "form-control", @Id = "Operator"})

In my action method I want to use var1 Operator var2.
Suppose 10 Operator  15 = 25 when Operator = "+"
Is it possible?

A:

Recently I was using open-source library for parsing math expressions provided as strings. The parser / evaluator name is mXparser.
http://mxparser.codeplex.com/
http://mathparser.org/
Example:
Expression e = new Expression("2+3/(4+1)");
double v = e.calculate();

Additionally - this software is using mXparser as well - you can learn the syntax Scalar Calculator app.
Best regards

