---
title: "Console Color Enumeration in C#"  
description: "In this article I am trying to explain the concept of Console Color Enumeration in C#."  
author: "Vijay Shukla"  
published: 2013-06-23  
updated: 2020-02-07  
canonical: https://www.mindstick.com/articles/1354/console-color-enumeration-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 3 minutes  

---

# Console Color Enumeration in C#

In this article I [am trying](https://answers.mindstick.com/qa/36834/which-two-programming-languages-should-i-master-in-if-i-am-trying-to-get-into-google-or-facebook) to [explain the concept](https://www.mindstick.com/forum/158822/explain-the-concept-of-abstract-classes-and-their-significance-in-oop) of Console Color [Enumeration](https://www.mindstick.com/blog/88/enumeration-in-c-sharp) 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](https://www.mindstick.com/interview/22939/what-are-constants-in-objective-c) that define foreground and background colors for the console.

##### Color member name

| ##### Member name | ##### Description |
| --- | --- |
| Black | The color black. |
| Blue | The [color blue](https://answers.mindstick.com/qa/31056/which-one-is-the-only-bird-that-can-see-the-color-blue). |
| Cyan | The color cyan (blue-green). |
| DarkBlue | The color dark blue. |
| DarkCyan | The color dark cyan (dark blue-green). |
| DarkGray | The color dark gray. |
| DarkGreen | The color dark green. |
| DarkMagenta | The color dark magenta (dark purplish-red). |
| DarkRed | The color dark red. |
| DarkYellow | The color dark yellow (ochre). |
| Gray | The color gray. |
| Green | The color green. |
| Magenta | The color magenta (purplish-red). |
| Red | The color red. |
| White | The color white. |
| Yellow | The color yellow. |

##### Console Color Enumeration Example:-

```
 class ConsoleColor
 {
 public static void Main()
 {
 String nl = Environment.NewLine;
 String[] colorNames = ConsoleColor.GetNames(typeof(ConsoleColor));
 Console.WriteLine("==================================================================");
 Console.WriteLine("Forecolor{0}", nl);
 Console.WriteLine("==================================================================");
 for (int x = 0; x < colorNames.Length; x++)
 {
 Console.Write("{0,2}: ", x+1);
 Console.BackgroundColor = ConsoleColor.Black;
 Console.ForegroundColor = (ConsoleColor)Enum.Parse(typeof(ConsoleColor), colorNames[x]);
 Console.Write("This is foreground color {0}.", colorNames[x]);
 Console.ResetColor();
 Console.WriteLine();
 }
 Console.WriteLine("==================================================================");
 Console.WriteLine("Backcolor{0}", nl);
 Console.WriteLine("==================================================================");
 for (int x = 0; x < colorNames.Length; x++)
 {
 Console.Write("{0,2}: ", x);
 Console.ForegroundColor = ConsoleColor.White;
 Console.BackgroundColor = (ConsoleColor)Enum.Parse(typeof(ConsoleColor), colorNames[x]);
 Console.Write("This is background color {0}.", colorNames[x]);
 Console.ResetColor();
 Console.WriteLine();
 }
 Console.ReadKey();
 }
 }
```

Code Description:-

1. Start the class.

3. Main method start

5. Create a string type nl [variable](https://www.mindstick.com/blog/11493/what-is-a-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 the console.

7. to 9. Give the user a [friendly](https://www.mindstick.com/articles/23189/5-sustainable-eco-friendly-products-to-look-out-for) message on the console screen.

10. This is [for loop](https://www.mindstick.com/forum/857/nested-for-loop-in-java-for-a-triangle) and this loop run colorNames.Length count.

13. Set the [background color](https://www.mindstick.com/forum/18/split-background-color) of the console.

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

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

16. This line of code resets the console color.

The rest of the code is performing same task for console background color.

##### Output: -

![Console Color Enumeration in C#](https://www.mindstick.com/mindstickarticle/5439252a-693c-427a-96a0-99afefe0c92b/images/8ddcef90-ce75-42b0-8b39-ae3386838d7c.png)

\

You should read this Article - **[Bootstrap Color Picker](https://www.mindstick.com/articles/1470/bootstrap-color-picker)**

---

Original Source: https://www.mindstick.com/articles/1354/console-color-enumeration-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
