c# - 控制台中的一行上有多种颜色
问题描述
我正在做一个项目,为此我想显示 CPU 架构是 64 位还是 32 位。现在,我已经有了:
bool is64 = Environment.Is64BitOperatingSystem;
if (is64) { Console.WriteLine("Architecture: 64 bit"); }
else { Console.WriteLine("Architecture: 32 bit"); }
但我想将“架构”显示为白色,将行的 64 位或 32 位部分显示为绿色。那可能吗?如果是这样,如果我能得到一个如何做的例子,我将不胜感激。
编辑
人们误解了这个问题。我的意思是这样的:
任何人?
解决方案
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.
推荐阅读
- python - Python - 带有进程的按钮
- docker - 允许 Docker for Mac 使用更多 CPU 的含义
- c++ - c ++将字符串引用包装在ostream中
- python - 多处理以实现流畅运行的 GUI
- curl - 中断的下载未在 curl 中恢复
- javascript - 将鼠标悬停在 Datamaps D3 JS 上时更新条形图
- javascript - discord.js 消息回复按钮
- c++ - C++优化内存读取速度
- javascript - Jest spyOn 没有正确计算 Angular 组件中的调用
- amazon-web-services - 当我想开始新的 AWS Transcribe 作业时,为什么会出现超时?