Click here to Skip to main content
15,905,322 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
C#
              namespace ConsoleApplication3
{
    class Program
    {
        public static void Main(string[] args)
        {
            int chess = 8;
            string dark = "x";
            string light = "y";
            for (var line1 = 0; line1 < chess; line1++) ;
            {
             for (var coloumn2 = 0; coloumn2 < chess; coloumn2++) ;
                {
                    string result;
                    if (LINE== 0)
                    {

                  }
                }
            }
        } } }

What I have tried:

I JUST WANT TO DECLARE THIS LINE1 VAR IN IF CONDITION HOW TO DO IT I AM NEW IN C# SORRY FOR THE SILLY QUESTION
Posted
Updated 19-Apr-16 16:44pm
v2
Comments
Wearwolf 19-Apr-16 11:34am    
In C# you can't declare a new variable in an if statement. What are you trying to test with that if statement?

Don't use var - use the actual variable type. It's not what's causing the problem in this case, it's that your caps KEY IS STUCK DOWN and you have spurious semicolons!

Try this:
C#
public static void Main(string[] args)
    {
    int chess = 8;
    string dark = "x";
    string light = "y";
    for (var line1 = 0; line1 < chess; line1++)
        {
        for (var column2 = 0; column2 < chess; column2++)
            {
            string result;
            if (line1 == 0)
                {
                ...
                }
            }
        }
    }

Semicolon is a statement terminator in C#, so when you put one at the end of your for loops:
C#
for (var line1 = 0; line1 < chess; line1++) ;
{
 for (var coloumn2 = 0; coloumn2 < chess; coloumn2++) ;
It ends the scope of the variable you declare within it.
 
Share this answer
 
thanks a lot @orginal griff I didn't noticed that @wearwolf thanks
 
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