微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

C# - string.IsNullOrEmpty 不适用于特定文本框

如何解决C# - string.IsNullOrEmpty 不适用于特定文本框

我刚刚学习编程,我正在尝试创建一个程序来计算飞机的重量和平衡。当您第一次加载此表单时,我希望指定的所有文本框的值都为 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()

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。