我希望我的表单显示当用户未输入数字或文本框为空白时弹出的错误消息。我努力了:
//If nothing is inserted in text, error box.
int value = 0;
if (string.IsNullOrWhitespace(txtBegin.Text) || !int.TryParse(txtBegin.Text, out value)) // Test for null or empty string or string is not a number
MessageBox.Show("Please enter a number!");
else
MessageBox.Show(string.Format("You entered: {0}!", value));
它给了我一个错误:'string' does not contain a definition for 'IsNullOrWhitespace'