How to change the Foreground Color of Text in C# Console?

CsharpServer Side ProgrammingProgramming

To change the Foreground Color of text, use the Console.ForegroundColor property in C#.

Example

Let us see an example −

using System;
class Demo {
   public static void Main (string[] args) {
      Console.BackgroundColor = ConsoleColor.Blue;
      Console.WriteLine("Background color changed = "+Console.BackgroundColor);
      Console.ForegroundColor = ConsoleColor.Yellow;
      Console.WriteLine("\nForeground color changed = "+Console.ForegroundColor);
   }
}

Output

This will produce the following output −

raja
Published on 13-Nov-2019 11:28:15
Advertisements