C# 中的 Console.SetBufferSize() 方法

csharpserver side programmingprogramming更新于 2025/10/8 11:28:00

C# 中的 Console.SetBufferSize() 方法用于将屏幕缓冲区的高度和宽度设置为指定值。

语法

语法如下 −

public static void SetBufferSize (int width, int height);

上面,参数 width 是缓冲区的宽度,而 height 是缓冲区的高度。

示例

现在让我们看一个在 C# 中实现 Console.SetBufferSize() 方法的示例 −

using System;
class Demo {
   public static void Main (string[] args) {
      Console.BackgroundColor = ConsoleColor.White;
      Console.ForegroundColor = ConsoleColor.Red;
      Console.SetBufferSize(400, 400);
      while (true) {
         Console.WriteLine("Our demo text!");
      }
   }
}

输出

这将产生以下输出 −


相关文章