Convert a string to an operator?

.net, c#, string

Solution

No, not the way you appear to be wanting to. A string literal, by definition, cannot be converted into an operator.

Problem

Possible Duplicate: Is there a string math evaluator in .NET? Is there a way to convert the operator code without doing a check for `"+", "-", "*", "/"` and then passing the value? ``` using System; namespace ConsoleApplication1 { class Program { private static void Main(string[] args) { string operator = "+"; int inputOne = 2; int inputTwo = 5; Console.WriteLine(Result(inputOne, inputTwo, operator)); Console.ReadLine(); } public static string Result(int one, int two, string computeOperator) { if (computeOperator == "+") { return (one + two).ToString(); } if (computeOperator == "-") { return (one - two).ToString(); } //and so on... return "0"; } } } ```

Original source

Related problems