簡體   English   中英

驗證字符串並在null或為空時顯示錯誤消息的C#問題

[英]C# problems with Validating String and displaying an error messages when null or empty

我正在嘗試獲取錯誤消息,以顯示兩個文本框是否為空,如果這樣的話,這將阻止表單處理任何數據。 當textboxPhoneNum.Text為空或用無效數據填充時,將顯示錯誤消息。

但是,當textboxName.Text為空時,它不會顯示,並且在應停止時也會處理所有代碼和數據。

        int Phone;  

        string Name = textboxName.Text;

      if (String.IsNullOrEmpty(Name))
        {
            if (int.TryParse(textboxPhoneNum.Text, out Phone))
            {

               code..

            }

            else
            {
                //comment
                MessageBox.Show("Please fill in name and phone number.");
            }
        }
        else
        {
            //comment
            MessageBox.Show("Please fill in name and phone number.");
        }
    }

可能缺少那一行的否定?

if (String.IsNullOrEmpty(Name))

if (!String.IsNullOrEmpty(Name))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM