2011-12-07 2 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); 

} 

경우이가 있지만 메시지 박스가 나타납니다.

시와 분 길이가 2 이상일 때 어떻게이 MessageBox를 표시 할 수 있습니까?

+0

"2 또는 plus"란 무엇을 의미합니까? 2 이상? 또한, "나는 시간을 넣지 않았다"는 의미는 무엇입니까? 뭐하고 있니? –

답변

5

대신에 | & & 연산자를 사용하십시오. 당신이 hours.Text.Lengthminute.Text.Length 2 또는 당신이 말한 것처럼 더 큰 값을 가지는 경우 상자를 표시하려면

+0

고맙습니다 =) – jolly

1

, 다음 코드는 다음과 같아야합니다

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