我有以下代码:
private void btnOK_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(tbVendorName.Text))
{
VendorName = tbVendorName.Text;
if (!string.IsNullOrEmpty(rtbVendorAddress.Text))
{
VendorAddress = rtbVendorAddress.Text;
if (!string.IsNullOrEmpty(tbVendorEmail.Text))
{
VendorEmail = tbVendorEmail.Text;
if (!string.IsNullOrEmpty(tbVendorWebsite.Text))
{
VendorWebsite = tbVendorWebsite.Text;
this.Close();
}
else
{
MessageBox.Show("Vendor Website Required");
}
}
else
{
MessageBox.Show("Vendor email is required");
}
}
else
{
MessageBox.Show("Vendor address is required");
}
}
else
{
MessageBox.Show("Vendor name is required");
}
}
但它看起来很可怕。有没有更好的办法?或者甚至是使代码更具可读性的替代方法?