Hello everyone, tell me, I have declared the variable timer equal to 0, so when I start it increases by 1, and then there is a comparison

if(timer >= 2) this.Hide(); 

And this code does not work, the program simply starts, and does not collapse ... why is that?

  • well, probably because after increasing the variable timer is equal to 1. A 1 <2 and the condition is not met. - KoVadim
  • Sorry, mistake. No, it is announced at the very beginning, and not at a specific event. - Angus123
  • Yes, I have nothing there anymore, it's all in the Form_Load event. - Angus123
  • @ Angus123, do step-by-step debugging and tell what the variable timer is equal at the time of comparison. - Olter
  • at start what it increases? if at startup all programs, then after any launch your timer variable is always = 1. - namak

2 answers 2

How your code works is “if (1 is greater than or equal to 2) we hide the form”.

Since 1 is not greater than or not equal to 2, the condition is not satisfied ... Is the secret revealed?

    if you see that the condition with the variable does not work, then before the if you can output the value of the variable to the console for debugging, and then everything will fall into place.