问题描述
我刚刚学习编程,我正在尝试创建一个程序来计算飞机的重量和平衡。当您第一次加载此表单时,我希望指定的所有文本框的值都为 0。我遇到了一个问题,其中一个框保持空白且未输入 0(袋重)。也许我错过了一些非常简单的东西?请看下面的代码:
tb1legBW.text = 这也是我指的袋子重量。
// This is setting the textBox values to 0 if they are blank.
if (string.IsNullOrEmpty(tb1LegOEW.Text) || string.IsNullOrEmpty(tb1LegPW.Text) || string.IsNullOrEmpty(tb1LegBW.Text) ||
string.IsNullOrEmpty(tb1LegFW.Text) || string.IsNullOrEmpty(tb1LegFuel.Text) || string.IsNullOrEmpty(tb1LegEquip.Text) ||
string.IsNullOrEmpty(tb1LegAWI.Text) || string.IsNullOrEmpty(tb1LegFB.Text) || string.IsNullOrEmpty(tb1LegCont.Text) ||
string.IsNullOrEmpty(tb1LegMTOW.Text) || string.IsNullOrEmpty(tb1LegGW.Text) || string.IsNullOrEmpty(tb1LegGD.Text) ||
string.IsNullOrEmpty(tb1LegMLW.Text) || string.IsNullOrEmpty(tb1LegLW.Text) || string.IsNullOrEmpty(tb1LegLGD.Text))
{
tb1LegOEW.Text = "0";
tb1LegPW.Text = "0";
tb1LegBW.Text = "0";
tb1LegFW.Text = "0";
tb1LegFuel.Text = "0";
tb1LegEquip.Text = "0";
tb1LegAWI.Text = "0";
tb1LegFB.Text = "0";
tb1LegCont.Text = "0";
tb1LegMTOW.Text = "0";
tb1LegGW.Text = "0";
tb1LegGD.Text = "0";
tb1LegMLW.Text = "0";
tb1LegLW.Text = "0";
tb1LegLGD.Text = "0";
}
当我运行程序时,袋重文本框是空白的,与其他文本框不同。附图片:When Program is ran
如果有人能给我一些关于正在发生的事情的见解?
解决方法
使用 string.IsNullOrWhitespace()