コード例 #1
0
ファイル: Program.cs プロジェクト: BartStodola/Host.App
        private static void Main(string[] args)
        {
            ILogger log = new Logger.Logger();

            log.Info("hello world.");

            ICalc calc = new Calc.Calc();
            var   r    = calc.Sub(1, 2);

            log.Warn($"result less than zero: {r}");

            Console.WriteLine("press any key!");
            Console.ReadLine();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Maximque/Calc
        static void Main()
        {
            count += 1;

            Console.ForegroundColor = ConsoleColor.Green;
            for (int i = 0; i < Console.BufferWidth; i += 1)
            {
                Console.Write('-');
            }

            if (count == 1)
            {
                Console.WriteLine("Доступные операторы:\n '+' - cложение\n '-' - вычитание\n '*' - умножение\n '/' - деление");
                for (int i = 0; i < Console.BufferWidth; i += 1)
                {
                    Console.Write('-');
                }
            }
            Console.ResetColor();

            Calc calculator = new Calc();
            Main();

        }
コード例 #3
0
        private Calc(string[] commandArray, int startIndex, string operatorParam, int level)
        {
            // mdMode: It's subgroup
            var mdMode      = (operatorParam == "*" || operatorParam == "/");
            var currentItem = MakeItem();

            Items     = new List <CalcAbstract>();
            LastIndex = -1;
            Operator  = operatorParam;
            isNoEmpty = true;

            // level++: Next level number
            Level = level++;

            for (var i = startIndex; i < commandArray.Length; i++)
            {
                var item = commandArray[i];

                // Convert Array to Graph
                switch (item)
                {
                case "": continue;

                case "-":
                {
                    if (mdMode && (currentItem.Minus || Items.Count > 0))
                    {
                        // Subgroup is ended
                        this.LastIndex = i - 1; return;
                    }
                    //  Symbol minus saved
                    currentItem.Minus = !currentItem.Minus; continue;
                }

                case "@":
                {
                    // Next item is variable
                    currentItem.Variable = true;
                    //currentItem.toString = function() { return (this.minus ? '-@' : '@') + this.variableName; };
                    continue;
                }

                case "+":
                {
                    if (mdMode)
                    {
                        // Subgroup is ended
                        this.LastIndex = i - 1; return;
                    }
                    if (currentItem.isNoEmpty)
                    {
                        Items.Add(currentItem);
                        currentItem = MakeItem();
                    }
                    continue;
                }

                case "*":
                case "/":
                {
                    if (item == "*" && currentItem.Minus)
                    {
                        throw new Exception("Invalid parsing. Multi...");
                    }

                    if (mdMode && Items.Count > 0)
                    {
                        // Subgroup is ended
                        this.LastIndex = i - 1; return;
                    }
                    if (currentItem.Minus)
                    {
                        throw new Exception("Invalid parsing. Minus");
                    }
                    // Make Subgroup
                    currentItem = new Calc(commandArray, i + 1, item, level);
                    Items.Add(currentItem);
                    if (currentItem.LastIndex == -1)
                    {
                        return;                                      // Parsing is finished
                    }
                    i           = currentItem.LastIndex;
                    currentItem = this.MakeItem();
                    continue;
                }

                case "(":
                {
                    // Make Subgroup
                    currentItem = new Calc(commandArray, i + 1, currentItem.Minus ? "-" : "+", level);
                    this.Items.Add(currentItem);
                    if (currentItem.LastIndex == -1)
                    {
                        return;                                      // Parsing is finished
                    }
                    i           = currentItem.LastIndex;
                    currentItem = this.MakeItem();
                    continue;
                }

                case ")":
                {
                    // Subgroup is ended
                    LastIndex = (operatorParam == "(" || operatorParam == "+" || operatorParam == "-") ? i : (i - 1); return;
                }

                default:
                {
                    currentItem.isNoEmpty = true;
                    if (currentItem.Variable)         // It's variable
                    {
                        currentItem.variableName = item;
                    }
                    else
                    {
                        // It's constante
                        try {
                            var valueFloat = Double.Parse(item);
                            currentItem.defaultValue = valueFloat * (currentItem.Minus ? -1 : 1);
                        }
                        catch
                        {
                            throw new Exception("Invalid parsing. Const=" + item);
                        }
                    }

                    this.Items.Add(currentItem);
                    currentItem = this.MakeItem();
                    continue;
                }
                }
            }

            this.Items.Add(currentItem);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: bushuevzi/CSharp_tutorials
        static void Main(string[] args)
        {
            Calc c = new Calc(10, 5);

            c.Add();
        }