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";
}
}
}