C# 中的 Console 类


C# 中的 Console 类用于表示控制台应用程序的标准输入、输出和错误流。

让我们看一些 C# 中 Console 类属性的示例 −

Console.CursorLeft 属性

要更改 C# 中 Console 的 CursorLeft,请使用 Console.CursorLeft 属性。

示例

让我们看一个示例 -

using System;
class Demo {
   public static void Main (string[] args) {
      Console.BackgroundColor = ConsoleColor.Blue;
      Console.WriteLine("Background color changed = "+Console.BackgroundColor);
      Console.ForegroundColor = ConsoleColor.Yellow;
      Console.WriteLine("
Foreground color changed = "+Console.ForegroundColor);       Console.CursorLeft = 30;       Console.Write("CursorLeft position: "+Console.CursorLeft);    } }

输出

这将产生以下输出 −

Console.CursorSize 属性

要更改 C# 中 Console 的 CursorSize,请使用 C# 中的 Console.CursorSize 属性。

示例

让我们看一个示例 -

using System;
class Demo {
   public static void Main (string[] args) {
      Console.BackgroundColor = ConsoleColor.Blue;
      Console.WriteLine("Background color changed = "+Console.BackgroundColor);
      Console.ForegroundColor = ConsoleColor.Yellow;
      Console.WriteLine("
Foreground color changed = "+Console.ForegroundColor);       Console.CursorSize = 1;       Console.WriteLine("
CursorSize = "+Console.CursorSize);    } }

输出

这将产生以下输出 −

Console.BufferWidth 属性

要更改 Console 的 BufferWidth,请使用 Console.BufferWidth 属性。

示例

让我们看一个示例 -

using System;
class Demo {
   public static void Main (string[] args) {
      Console.BufferHeight = 200;
      Console.WriteLine("Buffer Height = "+Console.BufferHeight);
      Console.BufferHeight = 250;
      Console.WriteLine("Buffer Width = "+Console.BufferWidth);
   }
}

输出

这将产生以下输出 −

Buffer Height = 200
Buffer Width = 200

更新时间: 2019 年 11 月 14 日

2000+ 阅读

开启您的

完成课程获得认证

开始
广告
© . All rights reserved.