【发布时间】:2018-10-29 17:22:19
【问题描述】:
如何获取当前控制台颜色(前景/背景)?
我有一种方法可以输出具有更改前景的单行:
public void ColorLine(string line, System.ConsoleColor foreground)
{
// maybe save original foreground color here
// then change it
System.Console.ForegroundColor = foreground;
// write line
System.Console.WriteLine(line);
// set original color
System.Console.ForegroundColor = // original foreground color;
}
【问题讨论】:
-
使用
Console.ForegroundColor并将其存储在变量中,例如var currentColor = Console.ForegroundColor;