Check if TextBox is empty and return MessageBox?

后端 未结 8 1380
谎友^
谎友^ 2020-12-23 22:19

I made this statement to check if TextBox is empty, but the MessageBox always shows up wether the TextBox is empty or not.

    private void NextButton_Click         


        
8条回答
  •  北荒
    北荒 (楼主)
    2020-12-23 22:44

    Try this condition instead:

    if (string.IsNullOrWhiteSpace(MaterialTextBox.Text)) {
        // Message box
    }
    

    This will take care of some strings that only contain whitespace characters and you won't have to deal with string equality which can sometimes be tricky

提交回复
热议问题