Namespace: System
Specifies colors for the console background and foreground text.
public enum ConsoleColor
The members of the ConsoleColor
enumeration represent the standard colors that can be used for the foreground and background of the console.
You can use these values with the Console.ForegroundColor
and Console.BackgroundColor
properties to change the colors of text displayed in the console.
using System;
public class Example
{
public static void Main()
{
// Save original colors
ConsoleColor originalForeground = Console.ForegroundColor;
ConsoleColor originalBackground = Console.BackgroundColor;
// Set new colors and write text
Console.ForegroundColor = ConsoleColor.Yellow;
Console.BackgroundColor = ConsoleColor.DarkBlue;
Console.WriteLine("This text is yellow on a dark blue background.");
// Restore original colors
Console.ForegroundColor = originalForeground;
Console.BackgroundColor = originalBackground;
Console.WriteLine("This text is back to the original colors.");
}
}