Write with console color - CSharp System.Drawing

CSharp examples for System.Drawing:Color

Description

Write with console color

Demo Code


using System;//  w  w  w .j a va2 s .  c  o  m

public class Main{
        public static void Write(ConsoleColor color, object obj)
        {
            Write(color, obj.ToString(), null);
        }
        public static void Write(ConsoleColor color, string format, params object[] objects)
        {
            ConsoleColor previousColor = Console.ForegroundColor;
            Console.ForegroundColor = color;
            if (objects == null)
            {
                Console.Write(format);
            }
            else
            {
                Console.Write(format, objects);
            }
            Console.ForegroundColor = previousColor;
        }
}

Related Tutorials