public static InstanceClass OperationClass(string Oper) { InstanceClass oper = null; switch (Oper) { case "+": oper = new AddClass(); break; case "-": oper = new SubtractClass(); break; case "*": oper = new MultiplyClass(); break; case "/": oper = new Division(); break; } return(oper); }
static void Main(string[] args) { InstanceClass operClass = null; //Console.WriteLine("请输入num1:"); operClass.Num1 = 1; //Console.WriteLine("请输入num2:"); operClass.Num2 = 2; Console.WriteLine("请输入符号:"); string oper = Console.ReadLine(); Operation.OperationClass(oper); double result = operClass.GetResult(); Console.WriteLine("运算结果是:" + result); Console.Read(); }