THREE COLORS REPEATED IN C# CONSOLE APPLICATION

Madam Walker

Total Post:22

Points:154
Posted by  Madam Walker
C# 
C#
 980  View(s)
Ratings:
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

  1. Ida B Wells

    Post:30

    Points:210
    Re: Three colors repeated in C# Console application

    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();

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!