如何使用 C# 清除螢幕?
使用 Console.Clear() 方法清除螢幕和控制檯緩衝區。呼叫 Clear 方法時,游標將自動滾動到視窗的左上角。
在此,我們已清除螢幕,然後設定 ForegroundColor 和 BackgroundColor −
ConsoleColor newForeColor = ConsoleColor.Blue; ConsoleColor newBackColor = ConsoleColor.Yellow;
以下是完整程式碼 −
示例
using System;
using System.Collections.Generic;
class Program {
static void Main() {
ConsoleColor foreColor = Console.ForegroundColor;
ConsoleColor backColor = Console.BackgroundColor;
Console.WriteLine("Clearing the screen!");
Console.Clear();
ConsoleColor newForeColor = ConsoleColor.Blue;
ConsoleColor newBackColor = ConsoleColor.Yellow;
}
}輸出
Clearing the screen!
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP