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.