日期:2014-05-18  浏览次数:20870 次

c#简单计算器 一个问题不懂。。
问题在代码注释中 为什么 用到bool 为什么在输出小数点的时候用到bool?



public partial class Form1 : Form
  {
  public Form1()
  {
  InitializeComponent();
  }
  double a, b, result;
  string action;
  bool isPoint; //为什么定义 这个bool

  private void button3_Click(object sender, EventArgs e)//以下是定义按钮数字
  {
  textBox1_ShowNum.Text += "3";
  }

  private void button5_Click(object sender, EventArgs e)
  {
  textBox1_ShowNum.Text += "5";
  }

  private void button7_Click(object sender, EventArgs e)
  {
  textBox1_ShowNum.Text += "7";
  }

  private void button1_Click(object sender, EventArgs e)
  {
  textBox1_ShowNum.Text += "1";
  }

  private void button2_Click(object sender, EventArgs e)
  {
  textBox1_ShowNum.Text += "2";
  }
  private void button4_Click(object sender, EventArgs e)
  {
  textBox1_ShowNum.Text += "4";
  }
  private void button6_Click(object sender, EventArgs e)
  {
  textBox1_ShowNum.Text += "6";
  }
  private void button8_Click(object sender, EventArgs e)
  {
  textBox1_ShowNum.Text += "8";
  }

  private void button9_Click(object sender, EventArgs e)
  {
  textBox1_ShowNum.Text += "9";
  }

  private void button_13_0_Click(object sender, EventArgs e)
  {
  textBox1_ShowNum.Text += "0";
  }

  private void button12_point_Click(object sender, EventArgs e)
  {
  if (!isPoint)//这里if 中为什么用到bool 实现的是什么功能? 为什么要 !isPoint 才 输出 "." 小数点
  {
  textBox1_ShowNum.Text += ".";
  }
  }
   
  private void button10_加法_Click(object sender, EventArgs e)//以下是定义 加减乘除运算
  {
  if (textBox1_ShowNum.Text.Length != 0)
  {
  a = double.Parse(textBox1_ShowNum.Text);
  }
  else
  {
  a = 0;
  }
  action = "1";
  textBox1_ShowNum.Text= " ";
  }

  private void button12_减法_Click(object sender, EventArgs e)
  {
  if (textBox1_ShowNum.Text.Length != 0)
  {
  a = double.Parse(textBox1_ShowNum.Text);
  }
  else
  {
  a = 0;
  }
  action = "2";
  textBox1_ShowNum.Text= " ";
  }
  private void button14_乘_Click(object sender, EventArgs e)
  {
  if (textBox1_ShowNum.Text.Length != 0)
  {
  a = double.Parse(textBox1_ShowNum.Text);
  }
  else
  {
&