Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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
