你好,請幫我在寫入開關語句否則下面的if語句如何使用switch語句,而不是太多否則如果
if(ClientAddressTextBox.Text == "")
{
MessageBox.Show("Please Enter Client Address");
this.ActiveControl = ClientAddressTextBox;
}
else if (InnerpathTextBox.Text == "")
{
MessageBox.Show("Please Enter Internal Path");
this.ActiveControl = InnerpathTextBox;
}
else if (InspectorIDTextBox.Text == "")
{
MessageBox.Show("Please Enter Inspector ID");
this.ActiveControl = InspectorIDTextBox;
}
else if (SerialNumberTextBox.Text == "")
{
MessageBox.Show("Please Enter Serial Number");
this.ActiveControl = SerialNumberTextBox;
}
在這種情況下,有什麼不妥使用'else if'。我會創建一個方法,將文本框和消息文本作爲參數,您可以在每個「else if」內調用以減少代碼行。 –
同樣我需要減少elseif爲下面的代碼請幫助 –
如何爲此else else(!compare.Contains(validate)) { MessageBox.Show(「您的型號名稱與OEM名稱不匹配「); this.ActiveControl = ModelTextBox; (「您的主機名稱與模型名稱不匹配」);或者(您的主機名稱與模型名稱不匹配);或者(您的主機名稱與模型名稱不匹配);或者(您的主機名稱與模型名稱不匹配)。 this.ActiveControl = HostNameTextBox; } @mathew –