Let's say you want to write a program in C# and compile it with command prompt. Assume the simple program only says;
Console.WriteLine("a" + "b" + "c" + "d");
Is it possible to make a, b, c, d print out in different colors on command prompt?
Let's say you want to write a program in C# and compile it with command prompt. Assume the simple program only says;
Console.WriteLine("a" + "b" + "c" + "d");
Is it possible to make a, b, c, d print out in different colors on command prompt?
yes. you must change the color and print your text like:
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("a");
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("b");
.
...
Use Console.ForegroundColor
property with ConsoleColor
enumeration.
Gets or sets the foreground color of the console.
Like;
public static void Main(string[] args)
{
Console.ForegroundColor = ConsoleColor.White;
string a = "a";
Console.WriteLine(a);
Console.ForegroundColor = ConsoleColor.Blue;
string b = "b";
Console.WriteLine(b);
Console.ForegroundColor = ConsoleColor.DarkGreen;
string c = "c";
Console.WriteLine(c);
Console.ForegroundColor = ConsoleColor.Red;
string d = "d";
Console.WriteLine(d);
}
Output will be;
The Console
class has the ForegroundColor
property that you can use:
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write(a);
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(b);
Console.ForegroundColor = ConsoleColor.Green;
Console.Write(c);
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(d);