我已经将缓冲区设置为其最大缓冲区大小(16位),但该应用程序将来将打印数百万行。
那我想你是说
Int16.MaxValue
而不是16个。
无论如何,要解决您的问题,只需恢复颜色
之前
写入行尾字符:
foreach (var i in Enumerable.Range(0, Console.BufferHeight + 3))
{
var fgColor = Console.ForegroundColor;
var bgColor = Console.BackgroundColor;
var tst = i % 2 == 0;
Console.ForegroundColor = tst ? ConsoleColor.White : ConsoleColor.Black;
Console.BackgroundColor = tst ? ConsoleColor.Black : ConsoleColor.Yellow;
Console.Write($"{i} HELLO WORLD");
Console.ForegroundColor = fgColor;
Console.BackgroundColor = bgColor;
Console.WriteLine();
}