Console.Clear Method in C#

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

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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");
    }
}
}

chevron_right


Output:

GeeksForGeeks
A Computer Science Portal
For Geeks

Program 2: Use clear() method to clear the console

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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();
    }
}
}

chevron_right


Output:




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.