if else string为null

jer*_*han 2 c# if-statement

我有两个文本框.如果textbox.text中的1为空,则MessageBox将显示提示用户他们没有完全输入字段.但它不起作用......

这是代码:

private void tab1nextButton_Click(object sender, RoutedEventArgs e)
{
    if ((AntcbatchpathTextBox.Text == null) || (MasterbuildpropertiespathTextBox.Text == null))
    {
        System.Windows.MessageBox.Show("You have not specified the paths completely!");

    }
    else
    {
        Tabitem2.Visibility = Visibility.Visible;
        Tabcontrol1.SelectedIndex = 1;

    }
}
Run Code Online (Sandbox Code Playgroud)

我试图添加断点来检查立即值.当Textbox.Text中的任何一个为空时,立即值分别为"".我的代码有什么问题吗?

ppi*_*icz 6

尝试 string.IsNullOrEmpty(AntcbatchpathTextBox.Text)

  • `IsNullOrWhiteSpace`可能会更好. (2认同)