如何在 C# 中获取当前的控制台前景色/背景色?

ex-*_*-vi 1 c# console-application

如何获得当前的控制台颜色(前景/背景)?

我有一种方法可以输出改变前景的单行:

    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;
    }
Run Code Online (Sandbox Code Playgroud)

use*_*994 5

// save original foreground color here
ConsoleColor currentForeground = Console.ForegroundColor;


// set original color
Console.ForegroundColor = currentForeground 
Run Code Online (Sandbox Code Playgroud)