public static ThreeElements Operation(string oper) { ThreeElements op = null; switch (oper) { case "+": op = new AddMethod(); break; case "-": op = new SubMethod(); break; case "*": op = new MulMethod(); break; case "/": op = new DivMethod(); break; } return(op); }
static void Main(string[] args) { ThreeElements p_One = new ThreeElements(); Console.WriteLine("请输入符号"); string oper = Console.ReadLine(); p_One = OperationMethod.Operation(oper); Console.WriteLine("请输入第一个数:"); p_One.NumOne = double.Parse(Console.ReadLine()); Console.WriteLine("请输入第二个数"); p_One.NumTwo = double.Parse(Console.ReadLine()); double result = p_One.result(); Console.WriteLine("结果是:" + result); Console.Read(); }