public static Test0 Get(string op) { Test0 t = null; switch (op) { case "+": t = new Test1(); break; case "-": t = new Test2(); break; } return(t); }
static void Main(string[] args) { Console.WriteLine("数字1"); var num1 = Console.ReadLine(); Console.WriteLine("数字2"); var num2 = Console.ReadLine(); Console.WriteLine("符号"); var fuhao = Console.ReadLine(); Test0 t = SimpleFactory.Get(fuhao); t.Num1 = num1; t.Num2 = num2; Console.WriteLine(t.GetResult()); Console.ReadKey(); }