2011-12-07 64 views
0

我有這個,如果多行的聲明如果

if (hours.Text.Length < 2 || minute.Text.Length < 2) 
{ 
    DialogResult dlgresult = MessageBox.Show("Insert Hour or Minute", 
              "First Application", 
              MessageBoxButtons.OK, 
              MessageBoxIcon.Error); 

} 

這將插入,而不分鐘的時間或沒有時間分鐘,但在MessageBox出現

當只有小時和分鐘的長度是2或更長時,如何顯示此MessageBox?

+0

你是什麼意思,「2或加號」?大於2?另外,「我已經插入了幾個小時」,這是什麼意思?你在插入什麼? –

回答

5

使用& &運算符而不是||。

+0

非常感謝=) – jolly

1

如果你想顯示框,如果hours.Text.Lengthminute.Text.Length具有2或更大像你說的價值,那麼你的代碼應該是:

if (hours.Text.Length >= 2 && minute.Text.Length >= 2) 
      { 
       DialogResult dlgresult = MessageBox.Show("Insert Hour or Minute", "First Application", 
         MessageBoxButtons.OK, MessageBoxIcon.Error); 

      } 

respectivley您可以使用下面的代碼來顯示如果其中任一變量> = 2,則框:

if (hours.Text.Length >= 2 || minute.Text.Length >= 2) 
       { 
        DialogResult dlgresult = MessageBox.Show("Insert Hour or Minute", "First Application", 
          MessageBoxButtons.OK, MessageBoxIcon.Error); 

      } 
+0

感謝Josh,這裏很少有錯別字;) – Makka