2011-12-07 67 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