Console Color Enumeration in C#

In this article I am trying to explain the concept of Console Color Enumeration in C#.

Console Color

We can be change the text and background colors. This sometimes makes programs easier to use. We change colors to make programs more easy-to-read. Errors and alerts are more noticeable. This leads to higher quality. Console Color Enumeration specified constants that define foreground and background colors for the console.

Color member name

Member name


The color black.


The color blue.


The color cyan (blue-green).


The color dark blue.


The color dark cyan (dark blue-green).


The color dark gray.


The color dark green.


The color dark magenta (dark purplish-red).


The color dark red.


The color dark yellow (ochre).


The color gray.


The color green.


The color magenta (purplish-red).


The color red.


The color white.


The color yellow.

Console Color Enumeration Example:-

1.  class ConsoleColor

2.  {

3.  public static void Main()

4.  {

5.  String nl = Environment.NewLine;

6.  String[] colorNames = ConsoleColor.GetNames(typeof(ConsoleColor));

7.  Console.WriteLine("==================================================================");

8.  Console.WriteLine("Forecolor{0}", nl);

9.  Console.WriteLine("==================================================================");

10. for (int x = 0; x < colorNames.Length; x++)

11. {

12. Console.Write("{0,2}: ", x+1);

13. Console.BackgroundColor = ConsoleColor.Black;

14. Console.ForegroundColor = (ConsoleColor)Enum.Parse(typeof(ConsoleColor), colorNames[x]);

15. Console.Write("This is foreground color {0}.", colorNames[x]);

16. Console.ResetColor();

17. Console.WriteLine();

18. }

19. Console.WriteLine("==================================================================");

20. Console.WriteLine("Backcolor{0}", nl);

21. Console.WriteLine("==================================================================");

22. for (int x = 0; x < colorNames.Length; x++)

23. {

24. Console.Write("{0,2}: ", x);

25. Console.ForegroundColor = ConsoleColor.White;

26. Console.BackgroundColor = (ConsoleColor)Enum.Parse(typeof(ConsoleColor), colorNames[x]);

27. Console.Write("This is background color {0}.", colorNames[x]);

28. Console.ResetColor();

29. Console.WriteLine();

30. }

31. Console.ReadKey();

32. }

33. }


Code Description:-

1.       Start the class.

3.       Main method start

5.       Create a string type nl variable which is save new line constant in the form of "/r/n".

6.       Create a string type array with colorNames name and in this array initialize the color names for console.

7.       to 9. Give the user friendly message on console screen.

10.   This is for loop and this loop run colorNames.Length count.

13.   Set the background color of console.

14.   Set the four-color of console text from Color Enumeration.

15.   This line of code give the message on console which color is set on text fore-color.

16.    This line of code reset the console color.

Rest of code is performing same task for console background color.

Output: -

Console Color Enumeration in C#


Leave Comment