コード例 #1
0
        public static 運算類別 ProduceOperator(string operatorStr)
        {
            switch (operatorStr)
            {
            case "+": oper = new Plus(); break;

            case "-": oper = new Minus(); break;

            case "*": oper = new Multiply(); break;

            case "/": oper = new Divide(); break;
            }
            return(oper);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Input NumberA:");
            string numberAStr = Console.ReadLine();

            Console.WriteLine("Input NumberB:");
            string numberBStr = Console.ReadLine();

            Console.WriteLine("Input Operator:");
            string operatorStr = Console.ReadLine();

            運算類別 oper = Factory.ProduceOperator(operatorStr);

            oper.NumberA = Convert.ToDouble(numberAStr);
            oper.NumberB = Convert.ToDouble(numberBStr);
            Console.WriteLine(oper.operation());
            Console.ReadKey();
        }