小编ex-*_*-vi的帖子

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

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

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

    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)

c# console-application

1
推荐指数
1
解决办法
664
查看次数

标签 统计

c# ×1

console-application ×1