[英]C# - string.IsNullOrEmpty not working for a specific textbox
我只是在學習編程,我正在嘗試創建一個程序來計算飛機的重量和平衡。 當您第一次加載此表單時,我希望所有指定的文本框的值都為 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";
}
當我運行程序時,包重量文本框是空白的,與其他的不同。 附圖:程序運行時
如果有人可以請給我一些關於正在發生的事情的見解?
使用 string.IsNullOrWhitespace()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.