C# 中的 Console.Clear 方法


C# 中的 Console.Clear 方法用于清除控制台缓冲区和显示信息对应的 控制台窗口。

语法

以下是语法 −

public static void Clear ();

示例

在实现 Console.Clear 方法之前,我们现在看一个示例 −

using System;
public class Demo {
   public static void Main(){
      Uri newURI1 = new Uri("https://tutorialspoint.com/");
      Console.WriteLine("URI = "+newURI1);
      Console.WriteLine("String representation = "+newURI1.ToString());
      Uri newURI2 = new Uri("https://tutorialspoint.com/jquery.htm#abcd");
      Console.WriteLine("
URI = "+newURI2);       Console.WriteLine("String representation = "+newURI2.ToString());       if(newURI1.Equals(newURI2))          Console.WriteLine("
Both the URIs are equal!");       else          Console.WriteLine("
Both the URIs aren't equal!");       Uri res = newURI1.MakeRelativeUri(newURI2);       Console.WriteLine("Relative uri = "+res); } }

输出

这会在使用 Console.Clear() 之前生成以下输出 −

URI = https://tutorialspoint.com/
String representation = https://tutorialspoint.com/
URI = https://tutorialspoint.com/jquery.htm#abcd
String representation = https://tutorialspoint.com/jquery.htm#abcd
Both the URIs aren't equal!
Relative uri = jquery.htm#abcd

示例

现在我们看同样的示例来实现 Console.Clear 方法 −

using System;
public class Demo {
   public static void Main(){
      Uri newURI1 = new Uri("https://tutorialspoint.com/");
      Console.WriteLine("URI = "+newURI1);
      Console.WriteLine("String representation = "+newURI1.ToString());
      Uri newURI2 = new Uri("https://tutorialspoint.com/jquery.htm#abcd");
      Console.WriteLine("
URI = "+newURI2);       Console.WriteLine("String representation = "+newURI2.ToString());       if(newURI1.Equals(newURI2))          Console.WriteLine("
Both the URIs are equal!");       else          Console.WriteLine("
Both the URIs aren't equal!");       Uri res = newURI1.MakeRelativeUri(newURI2);       Console.WriteLine("Relative uri = "+res);       Console.Clear();       Console.WriteLine("Console cleared now!");    } }

输出

这会生成以下输出 −

Console cleared now!

更新时间: 2019 年 11 月 7 日

已阅读 145 次

开启您的 职业生涯

完成课程获取认证

立即开始
广告