重複の可能性:
.NET に文字列数学エバリュエーターはありますか?
"+", "-", "*", "/"
値をチェックしてから渡すことなく、演算子コードを変換する方法はありますか?
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";
}
}
}