此方法用於清除控製台緩衝區和相應的顯示信息控製台窗口。
用法: 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#。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
