स्क्रीन और कंसोल बफ़र को साफ़ करने के लिए कंसोल.क्लियर () विधि का उपयोग करें। जब Clear मेथड को कॉल किया जाता है, तो कर्सर स्वतः ही विंडो के ऊपरी-बाएँ कोने में स्क्रॉल हो जाता है।
यहां, हमने स्क्रीन को साफ कर दिया है और फिर अग्रभूमि रंग और पृष्ठभूमि रंग सेट कर दिया है -
ConsoleColor newForeColor = ConsoleColor.Blue; ConsoleColor newBackColor = ConsoleColor.Yellow;
निम्नलिखित पूरा कोड है -
उदाहरण
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;
}
} आउटपुट
Clearing the screen!