C# Console => Change Background and Foreground Colors

A basic C# console background and foreground color tutorial.

What we do :

  • Set background color and foreground color of Console.
using System;

namespace Example_A
{
    class Program
    {
        static void Main(string[] args)
        {
            //SET COLORS
            Console.ForegroundColor=ConsoleColor.Cyan;
            Console.BackgroundColor=ConsoleColor.Gray;

            //PROMPT
            Console.WriteLine( "Whats You Name ?" );

            //get name
            string name = Console.ReadLine();

            //RESET FOREGROUND COLOR
            Console.ForegroundColor = ConsoleColor.Blue;

            //GREET
            Console.WriteLine("Hello "+name);

            //WAIT FOR KEY TO EXIT
            Console.ReadKey();
        }
    }
}

Cheers.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *