Skip to content
← Back to Community
Colourful C# Console!
Profile icon
MattDESTROYER

The C# console is a bit plain so in this 'tutorial' we will learn how to make C# Console apps a little more colourful!

The C# console has two properties which we will be using, one is Console.ForegroundColor and the other is Console.BackgroundColor.

For the colours we will be using an enum called ConsoleColor.

All colours:

  • ConsoleColor.Black
  • ConsoleColor.Blue
  • ConsoleColor.Cyan
  • ConsoleColor.DarkBlue
  • ConsoleColor.DarkCyan
  • ConsoleColor.DarkGray
  • ConsoleColor.DarkGreen
  • ConsoleColor.DarkMagenta
  • ConsoleColor.DarkRed
  • ConsoleColor.DarkYellow
  • ConsoleColor.Gray
  • ConsoleColor.Green
  • ConsoleColor.Magenta
  • ConsoleColor.Red
  • ConsoleColor.White
  • ConsoleColor.Yellow

Console.ForegroundColor changes the font colour of anything printed to the console. Console.BackgroundColor changes the highlight or background colour of anything printed to the console. We can set these to any of the ConsoleColors in the ConsoleColor enum.

Let's change the font colour to red with a gray background:

Console.ForegroundColor = ConsoleColor.Red; Console.BackgroundColor = ConsoleColor.Gray; Console.WriteLine("Red with a gray background!");

We can even change the colour of individual characters using Console.Write()

Console.ForegroundColor = ConsoleColor.Red; Console.Write("R"); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.Write("a"); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("i"); Console.ForegroundColor = ConsoleColor.Blue; Console.Write("n"); Console.ForegroundColor = ConsoleColor.DarkBlue; Console.Write("b"); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.Write("o"); Console.ForegroundColor = ConsoleColor.Green; Console.Write("w"); Console.ResetColor(); Console.Write("\n");

Now you can add a little colour to your console creations!

Voters
Profile icon
ch1ck3n
Profile icon
VulcanWM
Profile icon
MattDESTROYER
Comments
hotnewtop
Profile icon
ch1ck3n

P R I D E

Profile icon
MattDESTROYER

@ch1ck3n Not what I intended but happy to be supporting :)

Profile icon
VulcanWM

Woah this is cool!

Profile icon
MattDESTROYER

@VulcanWM Thanks, it's my first tutorial lol :)

Profile icon
VulcanWM