Learn to Code via Tutorials on Repl.it!

← Back to all posts
Colourful C# Console!
h
MattDESTROYER (20)

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!

Comments
hotnewtop
MattDESTROYER (20)

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

VulcanWM (2912)

Woah this is cool!

MattDESTROYER (20)

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