如何获取当前控制台颜色(前景/背景)?
我有一个方法来输出改变前景的单行:
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;
}
答案 0 :(得分:3)
// save original foreground color here
ConsoleColor currentForeground = Console.ForegroundColor;
// set original color
Console.ForegroundColor = currentForeground