Click here to Skip to main content
15,888,340 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
Actually i am totallynew in C# 2010
so i have simple problem in IF Statement

So my code is
C#
private void Timer1_Tick(object sender, EventArgs e)
{
   ProgressBar1.Value += 1;

   if (ProgressBar1.Value<=10)
   {
      Label1.Text = "Loading Application . . .";
   }    
   else if (ProgressBar1.Value <= 20)
   {
   }
   else if (ProgressBar1.Value <= 40)
   {
   }
   else if (ProgressBar1.Value <= 60)
   {
   }
   else if (ProgressBar1.Value <= 80)
   {
   }
  else if (ProgressBar1.Value <= 100)
  {
    Label1.Text = "Starting Application . . .";
  }
    If(ProgressBar1.Value == 100)
  {
     Timer1.Dispose();
            
    }
 }

The name 'If' does not exist in the current context error i getting

/Edit Pre Tag added by Jibesh
Posted
Updated 13-Jan-13 18:47pm
v2

The error means the Keyword If is wrong you should use small if as you define above.

if you are using visual studio 'if' keyword will turn blue color normally. in the above case you used a capital If which is not a keyword.
 
Share this answer
 
Welcome to the world of C# programming. Since you are new, you should concentrate on understanding the basics and syntaxes in C# programming instead of directly jumping to programming.

Your lesson for today is - C# is a case-sensitive language. So a 'If' is not equal to 'if'

C# syntax for 'if' statement is
C#
if(<<condition that evaluates to bool>>)
{
//Your code here
}
 
Share this answer
 
Correct spellings of "if". its "if" and you are writing "If" see the capital "I" you placed instead of "i" in the last if

C#
If(ProgressBar1.Value == 100)
 {
    Timer1.Dispose();

   }


should be

C#
if(ProgressBar1.Value == 100)
 {
    Timer1.Dispose();

   }
 
Share this answer
 
Did you ever heard that C# is a case-sensitive language? This is the solution of your problem. :-)

—SA
 
Share this answer
 
use else at the end of all last else statement.
else
{
}
 
Share this answer
 
It is missing
else block .

you can use
else
{
}

before the last If statement.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900