Пример #1
0
        private void result()
        {
            String op;
            int    iOp = 0;

            if (tb.Text.Contains("+"))
            {
                iOp = tb.Text.IndexOf("+");
            }
            else if (tb.Text.Contains("-"))
            {
                iOp = tb.Text.IndexOf("-");
            }
            else if (tb.Text.Contains("*"))
            {
                iOp = tb.Text.IndexOf("*");
            }
            else if (tb.Text.Contains("/"))
            {
                iOp = tb.Text.IndexOf("/");
            }

            op = tb.Text.Substring(iOp, 1);

            string firstNum = tb.Text.Substring(0, iOp);
            string secNum   = tb.Text.Substring(iOp + 1, tb.Text.Length - iOp - 1);
            double op1      = Convert.ToDouble((Convert.ToInt32(firstNum, this.curBase)));
            double op2      = Convert.ToDouble((Convert.ToInt32(secNum, this.curBase)));
            double res;

            if (op == "+")
            {
                res = op1 + op2;
            }
            else if (op == "-")
            {
                res = op1 - op2;
            }
            else if (op == "*")
            {
                res = op1 * op2;
            }
            else
            {
                res = op1 / op2;
            }
            if (curBase == 16)
            {
                tb.Text = MatUtil.DoubleToHex(res);
            }
            else if (curBase == 10)
            {
                tb.Text = res.ToString("F2");
            }
            else
            {
                tb.Text = Convert.ToString(Convert.ToInt32(res), curBase);
            }
        }