public static Operation choose(string s) { switch (s) { case "+": oper = new OperationAdd(); break; case "-": oper = new OperationMinus(); break; case "*": oper = new OperationRide(); break; case "/": oper = new OperationDiv(); break; } return(s); }
private void btnCount_Click(object sender, EventArgs e) { if (txtNum1.Text.Trim().Equals(string.Empty)) { MessageBox.Show("操作数不能为空!"); this.txtNum1.Focus(); return; } if (txtNum2.Text.Trim().Equals(string.Empty)) { MessageBox.Show("被操作数不能为空!"); this.txtNum2.Focus(); return; } try { string s = this.cbxSign.SelectedItem.ToString().Trim(); Operation oper = new Operation(); switch (s) { case "+": oper = new OperationAdd(); break; case "-": oper = new OperationMinus(); break; case "*": oper = new OperationRide(); break; case "/": oper = new OperationDiv(); break; } oper.NumberA = double.Parse(this.txtNum1.Text.Trim()); oper.NumberB = double.Parse(this.txtNum2.Text.Trim()); this.lblResult.Text = oper.GetReault().ToString(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }