![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to clear screen using C#?
Use the Console.Clear() method to clear screen and the console buffer. When the Clear method is called, the cursor automatically scrolls to the top-left corner of the window.
Here, we have cleared the screen and then set the ForegroundColor and BackgroundColor −
ConsoleColor newForeColor = ConsoleColor.Blue; ConsoleColor newBackColor = ConsoleColor.Yellow;
The following is the complete code −
Example
using System; using System.Collections.Generic; class Program { static void Main() { ConsoleColor foreColor = Console.ForegroundColor; ConsoleColor backColor = Console.BackgroundColor; Console.WriteLine("Clearing the screen!"); Console.Clear(); ConsoleColor newForeColor = ConsoleColor.Blue; ConsoleColor newBackColor = ConsoleColor.Yellow; } }
Output
Clearing the screen!
Advertisements