如何使用 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