在.NET中,是否可能以彩色方式向控制台中写入内容?

47 浏览
0 Comments

在.NET中,是否可能以彩色方式向控制台中写入内容?

编写一个小的命令行工具,输出不同颜色的内容会很不错。这可能吗?

admin 更改状态以发布 2023年5月21日
0
0 Comments

class Program
{
    static void Main()
    {
        Console.BackgroundColor = ConsoleColor.Blue;
        Console.ForegroundColor = ConsoleColor.White;
        Console.WriteLine("White on blue.");
        Console.WriteLine("Another line.");
        Console.ResetColor();
    }
}

引用自 这里

0
0 Comments

是的。可以看看这篇文章。以下是来自该文章的示例:

Console.BackgroundColor = ConsoleColor.Blue;
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("White on blue.");

enter image description here

0