在Windows窗体中切换语句 [英] Switch statement in windows forms
问题描述
Hello
我正在使用switch语句创建一个窗体。但它不起作用。谁能帮我?目的是计算一个人的理想体重和 一个女人,男人理想体重的公式是:(长度 - 100)/ 1,1。
的公式是女人的理想体重:(长+ 4 *手腕围 - 100)/ 2.
I was making a windows forms with a switch statement. But it don't work. Can anyone help me? The intention is to calculate the ideal weigth of a man and a woman, the formula for the ideal weight of the man is: (length - 100) / 1,1. The formula for the ideal weight of the woman is: (length + 4 * wrist circumference - 100)/2.
这是我的代码。
                   
          private void btnIdeaalGewicht_Click(object sender,EventArgs e)
      {
         串性;
         双倍长度,重量,WristCircumference,idealweightman,idealweightwoman;
          sex = txtsex.Text;
          length = Convert.ToDouble(txtlength.Text);
          weight = Convert.ToDouble(txtweight.Text);
          WristCircumference  = Convert.ToDouble(txtpolsWristCircumference.Text);
          idealweightman = length - 100 / 1.1;
          idealweightwoman =(长度+(4 * WristCircumference) - 100)/ 2;
         开关(Convert.ToDouble(性别))
          {
             案例1:
              case(sex =="man"):
                  MessageBox.Show("你的理想体重是+ + idealweightman +"。"","理想体重",MessageBoxButtons.OK);
                 休息;
          }¥b $ b       }¥b $ b   }
}
private void btnIdeaalGewicht_Click(object sender, EventArgs e)
{
string sex;
double length, weight, WristCircumference, idealweightman, idealweightwoman;
sex = txtsex.Text;
length = Convert.ToDouble(txtlength.Text);
weight = Convert.ToDouble(txtweight.Text);
WristCircumference = Convert.ToDouble(txtpolsWristCircumference.Text);
idealweightman = length - 100 / 1.1;
idealweightwoman = (length + (4 * WristCircumference) - 100) / 2;
switch (Convert.ToDouble(sex))
{
case 1:
case (sex == "man"):
MessageBox.Show("Your ideal weight is " + idealweightman + ".", "Ideal weight", MessageBoxButtons.OK);
break;
}
}
}
}
推荐答案
当出现这样的问题时,我建议在代码中设置一个断点,例如在line sex = txtsex.Text上,当您通过代码点击断点步骤时,检查值和代码流。这会导致逻辑无效或误解为
逻辑。
When there are issues such as this I suggest setting a break-point in your code, e.g. on the line sex = txtsex.Text, when you hit the break-point step thru the code, examine values and flow of code. This will lead you to invalid logic or misinterpreted logic.
这篇关于在Windows窗体中切换语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!