当我通过C#学习方法时,我正在编写一些地牢爬虫。我正在使用Visual Studio,该应用程序是“控制台应用程序(.NET Framework)”。我的问题是我在主菜单中有一个选项可以更改文本颜色,而我试图在其他所有时间更改颜色时都进行更改,以使其恢复为默认设置。
我尝试将颜色分配给变量,可以说是default,然后执行Console.ForegroundColor = ConsoleColor.default;我到处都在网上看,找不到修复程序。
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("example");
Console.ForgroundColor = Console.Color.White;
// This needs to be default ^^
答案 0 :(得分:0)
您可以创建一个属性ConsoleColor
,它将被视为默认颜色。
只需在您希望将默认颜色设置为Console.ForegroundColor
类似
public class Program
{
public static ConsoleColor DefaultColor { get; set; } = ConsoleColor.Black;
public static void Main(string[] args)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("example");
//You can use DefaultColor whenever you want to assign default color to Foreground
Console.ForegroundColor = DefaultColor;
}
}