此方法用于清除控制台缓冲区和相应的显示信息控制台窗口。
用法: public static void Clear ();
异常:如果发生I /O错误,则此方法将引发IOException。
下面的程序显示Console.Clear()方法的使用:
示例1:在使用Clear方法之前显示内容
// C# program to illustrate the use 
// of Console.Clear Method  
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading; 
using System.Threading.Tasks; 
  
namespace GFG { 
  
class Program { 
  
    static void Main(string[] args) 
    { 
  
        // Print the statements 
        Console.WriteLine("GeeksForGeeks"); 
        Console.WriteLine("A Computer Science Portal"); 
        Console.WriteLine("For Geeks"); 
    } 
} 
}
输出:
GeeksForGeeks A Computer Science Portal For Geeks
示例2:使用clear()方法清除控制台
// C# program to illustrate the use 
// of Console.Clear Method  
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading; 
using System.Threading.Tasks; 
  
namespace GFG { 
  
class Program { 
  
    static void Main(string[] args) 
    { 
        // Print the statements 
        Console.WriteLine("GeeksForGeeks"); 
        Console.WriteLine("A Computer Science Portal"); 
        Console.WriteLine("For Geeks"); 
  
        // Clear the Console 
        Console.Clear(); 
    } 
} 
}
输出:
相关用法
- C# Uri.IsBaseOf(Uri)用法及代码示例
- C# Uri.FromHex()用法及代码示例
- C# Uri.IsHexDigit()用法及代码示例
- C# Random.Next()用法及代码示例
- C# Math.Log()用法及代码示例
- C# Queue.Contains()用法及代码示例
- C# Uri.GetHashCode()用法及代码示例
- C# DateTimeOffset.Add()用法及代码示例
注:本文由纯净天空筛选整理自Kirti_Mangal大神的英文原创作品 Console.Clear Method in C#。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
