参考书目:C#6.0学习笔记——从第一行C#代码到第一个项目设计(作者周家安)P133
学习目的:设置控制台窗口的文本颜色
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace Example3_6
{
class Program
{
static void Main(string[] args)
{
//修改窗口标题文本
Console.Title = "我的应用程序";
//将文本颜色改为绿色
Console.ForegroundColor = ConsoleColor.Green;
WriteLine("第一行文本。");
//将文本背景色改为蓝色
Console.BackgroundColor = ConsoleColor.Blue;
WriteLine("第二行文本。");
//将文本背景色改为白色
Console.BackgroundColor = ConsoleColor.White;
WriteLine("第三行文本。");
//将文本颜色改为黑色
Console.ForegroundColor = ConsoleColor.Black;
WriteLine("第四行文本。");
//将文本颜色还原为灰色
Console.ForegroundColor = ConsoleColor.Gray;
WriteLine("第五行文本。");
//将文本背景色还原为黑色
Console.BackgroundColor = ConsoleColor.Black;
WriteLine("第六行文本。");
ReadKey();
}
}
}
运行结果如下: