コード例 #1
0
        private static decimal?CalculateBinary(BinaryOperation <double, double> operation)
        {
            switch (operation.Operator)
            {
            case "log":
                return((decimal)Math.Log(operation.Right, operation.Left));

            case "^":
                return((decimal)Math.Pow(operation.Left, operation.Right));
            }

            return(null);
        }
コード例 #2
0
        private static decimal?CalculateBinary(BinaryOperation <decimal, decimal> operation)
        {
            switch (operation.Operator)
            {
            case "+":
                return(operation.Left + operation.Right);

            case "-":
                return(operation.Left + operation.Right);

            case "*":
                return(operation.Left * operation.Right);

            case "/":
                return(operation.Left / operation.Right);
            }

            return(null);
        }
コード例 #3
0
        public static void Main(string[] args)
        {
            decimal?result = null;

            if (args.Length == 3)
            {
                var op = BinaryOperation.Parse(args);
                result = CalculateBinary((dynamic)op);
            }
            else if (args.Length == 2)
            {
                var op = args[0];
                result = CalculateUnary(op, args[1]);
            }

            if (result == null)
            {
                Console.WriteLine("Złe argumenty");
            }
            else
            {
                Console.WriteLine($"Wynik: {result}");
            }
        }