views:

146

answers:

2

Writing a small command line tool, it would be nice to output in different colours. Is this possible?

+7  A: 
class Program
{
    static void Main()
    {
        Console.BackgroundColor = ConsoleColor.Blue;
        Console.ForegroundColor = ConsoleColor.White;
        Console.WriteLine("White on blue.");
        Console.WriteLine("Another line.");
        Console.ResetColor();
    }
}

Taken from here.

Darin Dimitrov
How did I miss something so obvious, lol. Thanks very much!
SLC
If you directly copy and paste someone else's content IMHO it is the good thing to do to link to the original source.
Mark Byers
@Mark, I agree with you but this means every time you write a single line of code you will need to quote MSDN because chances are, it is already written in the documentation. But you are right, I should have provided a link to the site. Updating my answer.
Darin Dimitrov
@Darin: Seen your update: Voted +1. :)
Mark Byers
+11  A: 

Yes. See this article. Here's an example from there:

Console.BackgroundColor = ConsoleColor.Blue;
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("White on blue.");

Mark Byers