0

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?

Omer Enes
  • 93
  • 1
  • 6
  • Possible duplicate of [Custom text color in C# console application?](https://stackoverflow.com/questions/7937256/custom-text-color-in-c-sharp-console-application) – Avi Meltser May 18 '19 at 12:32
  • See the definition of `ConsoleColor` [here](https://learn.microsoft.com/en-us/dotnet/api/system.consolecolor?view=netframework-4.8) – Peter Smith May 18 '19 at 12:40

1 Answers1

1

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.

Ofir Winegarten
  • 9,215
  • 2
  • 21
  • 27