Omer Enes
Omer Enes

Reputation: 93

multiple colors on one line in console

i'm working on a project, and for that i want to display if the CPU architecture is 64 or 32 bit. Now, i already have that:

 bool is64 = Environment.Is64BitOperatingSystem;
 if (is64) { Console.WriteLine("Architecture: 64 bit"); }
 else { Console.WriteLine("Architecture: 32 bit"); }

But i want to display the "Architecture" white, and the 64 bit or 32 bit part of the line green. is that possible? if so, i would appreciate it if I get an example of how to do it.

EDIT

people misunderstand this question. i mean something like this:

enter image description here

Anyone?

Upvotes: 0

Views: 253

Answers (1)

Ofir Winegarten
Ofir Winegarten

Reputation: 9365

Simple:

You set the color to White then Use Console.Write to output "Architecture".
Then, Set the color to Green and use Console.WriteLine to output the bit part.

Console.ForegroundColor = ConsoleColor.White;
Console.Write("Architecture: ");
Console.ForegroundColor = ConsoleColor.Green;
bool is64 = Environment.Is64BitOperatingSystem;
if (is64) { Console.WriteLine("64 bit"); }
else { Console.WriteLine("32 bit"); }

You might want save the original ForegroundColor aside, so you can restore it after.

Upvotes: 1

Related Questions