gpt-4-1106-preview· openai
Suzhen/CodeChat
How to output colored text in console in c#?
- User
How to output colored text in console in c#?
- Assistant
In C#, you can change the console text color using the
Console.ForegroundColorandConsole.BackgroundColorproperties. These properties accept values from theConsoleColorenumeration, which includes various colors.Here's a simple example to output colored text to the console:
csharpusing System; class Program { static void Main() { // Set the text color to green Console.ForegroundColor = ConsoleColor.Green; // Output colored text Console.WriteLine("This text will be green!"); // Reset the text color to its default value Console.ResetColor(); // Continue with the program... } }