Home > DeveloperSection > Forums > Three colors repeated in C# Console application
Madam Walker
Madam Walker

Total Post:22

Points:154
Posted on    October-05-2013 7:47 AM

 C# C# 
Ratings:


 1 Reply(s)
 700  View(s)
Rate this:

I am new in C#.

Below is my code this code I have done so far:

for (int row = 1; row <= 25; row++)
        {
            for (int col = 1; col <= 39; col++)
            {
                switch (row)
                {
                    case 1:
                        Console.ForegroundColor = ConsoleColor.Red;
                        break;
                    case 2:
                        Console.ForegroundColor = ConsoleColor.White;
                        break;
                    case 3:
                        Console.ForegroundColor = ConsoleColor.Green;
                        break;
                }
                Console.Write("@ ");                    
        }
        Console.WriteLine();
In the above line of code the first line is shows in red color after that all lines is shows in white color how can I achieve my task please anybody help me

All help is appreciated

Thanks



Ida B Wells
Ida B Wells

Total Post:30

Points:210
Posted on    October-05-2013 9:00 AM

Change your code in switch:

for (int row = 1; row <= 25; row++) {
                for (int col = 1; col <= 39; col++)
                {
                    switch (row%3)
                    {
                        case 1:
                            Console.ForegroundColor = ConsoleColor. Red;
                            break;
                        case 2:
                            Console.ForegroundColor = ConsoleColor. White;
                            break;
                        case 0:
                            Console.ForegroundColor = ConsoleColor.Green;
                            break;
                     }
                     Console.Write("@ ");        
                    }
                Console.WriteLine();

Don't want to miss updates? Please click the below button!

Follow MindStick