Пример #1
0
        static void Main(string[] args)
        {
            Mathematics     m              = new Mathematics();
            IArithmatic     arithmatic     = new Mathematics(); // upcasting
            IMoreArithmatic moreArithmatic = new Mathematics(); // upcasting

            Console.WriteLine($"Substraction result  { arithmatic.Subs(45, 6)}");
            Console.WriteLine($"Substraction more result  { moreArithmatic.Subs(45, 6)}");
            Console.WriteLine($"Addition result {m.Add(12, 23, 25, 56)}");
            // Named parameters
            Console.WriteLine($"Division result {m.Divide(deno:9, num:36)}");
        }
Пример #2
0
        private static int Calculate(Commands command, int first, int second)
        {
            switch (command)
            {
            case Commands.add:
                return(Mathematics.Add(first, second));

            case Commands.sub:
                return(Mathematics.Sub(first, second));

            default:
                throw new InvalidOperationException("Unknown command in calculator");
            }
        }
Пример #3
0
        private int Calculate(Commands command, int first, int second)
        {
            switch (command)
            {
            case Commands.add:
                return(mathematic.Add(first, second));

            case Commands.sub:
                return(mathematic.Substract(first, second));

            case Commands.mul:
                return(mathematic.Multiple(first, second));

            default:
                throw new InvalidOperationException("Unknown command in calculator");
            }
        }