Beispiel #1
0
        private void butIgual_Click(object sender, EventArgs e)
        {
            Match  coincidencia;
            string numero = @"-?[\d]+(\,[\d]+)?";

            coincidencia = Regex.Match(txtOperacion.Text, numero);
            decimal[] numeros = new decimal[2];
            int       indice  = 0;

            while (coincidencia.Success)
            {
                numeros[indice++] = Decimal.Parse(coincidencia.Value);
                coincidencia      = coincidencia.NextMatch();
            }
            if (indice == 2)
            {
                try
                {
                    decimal resultado = operacion.Operar(numeros[0], numeros[1]);
                    txtOperacion.Text = resultado.ToString();
                } catch (Exception ex)
                {
                    txtOperacion.Text = ex.Message;
                }
                deshabilitarTodo();
                butReset.Enabled = true;
            }
        }