Last Updated : 29 Jan, 2019
This method is used to clear the console buffer and corresponding console window of display information.
Syntax: public static void Clear (); Exceptions: This method throws IOException if an I/O error occurred.
Below programs show the use of Console.Clear() method:
Program 1:To display the contents before the use of Clear method
csharp
// 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");
}
}
}
Output:
GeeksForGeeks A Computer Science Portal For GeeksProgram 2:
Use clear() method to clear the console
csharp
// 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();
}
}
}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4