请帮我系统。我不知道isnullorwhitespace
:
我的错误是:
“string确实包含isnullorwhitespace的定义”
isnullorwhitespace
的其他选择是什么?
private void btnAdd_Click(object sender, EventArgs e)
{
int age = int.Parse(txtage.Text);
if (string.IsNullOrWhiteSpace(txtfname.Text))
{
MessageBox.Show("Please input your firstname!");
}
else if(string.IsNullOrWhiteSpace(txtlname.Text))
{
MessageBox.Show("Please input your lastname!");
}
else if(string.IsNullOrWhiteSpace(cbgender.SelectedItem.ToString()))
{
MessageBox.Show("Please specify your gender!");
}
else if(string.IsNullOrWhiteSpace(txtage.Text) || age <= 0 )
{
MessageBox.Show("Please assign your birthdate to know your age!");
}
else if(string.IsNullOrWhiteSpace(txtcontact.Text))
{
MessageBox.Show("Please input your contact number!");
}
else if(string.IsNullOrWhiteSpace(txtAddress.Text))
{
MessageBox.Show("Please input your address!");
}
else if(string.IsNullOrWhiteSpace(txtUsername.Text))
{
MessageBox.Show("Please input your username!");
}
else if(string.IsNullOrWhiteSpace(txtPass.Text))
{
MessageBox.Show("Please input your password!");
}
else if(string.IsNullOrWhiteSpace(cbxQuest.SelectedItem.ToString()))
{
MessageBox.Show("Please specify your secret question!");
}
else if(string.IsNullOrWhiteSpace(txtAsnwer.Text))
{
MessageBox.Show("Please input your answer!");
}
else
{
//Insert 7
ui.fname = txtfname.Text;
ui.lname = txtlname.Text;
ui.gender = cbgender.SelectedItem.ToString();
ui.age = int.Parse(txtage.Text);
ui.bdate = dtpBdate.Value;
ui.contactNo = txtcontact.Text;
ui.Adress = txtAddress.Text;
//Insert 4
us.username = txtUsername.Text;
us.passwordHash = txtPass.Text;
us.secretQuestion = cbxQuest.SelectedItem.ToString();
us.secretAnswer = txtAsnwer.Text;
StoredProcedure.Insert(ui, us);
dgData.DataSource = StoredProcedure.View();
Clear();
}
答案 0 :(得分:1)
String.IsNullOrWhiteSpace已在.NET 4中引入。如果您不是针对.NET 4,那么您可以轻松编写自己的:
//options has information like hostname, path, etc.
var req = https.request(options, function(res) {
res.setEncoding('utf8');
res.on('data', function (response) {
console.log(response); //this is the JSON that you're seeing
item = JSON.parse(response);
console.log(item.kind);
});
});
可以像这样使用:
public static class StringExtensions
{
public static bool IsNullOrWhiteSpace(string value)
{
if (value != null)
{
for (int i = 0; i < value.Length; i++)
{
if (!char.IsWhiteSpace(value[i]))
{
return false;
}
}
}
return true;
}
}