- Trending Categories
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
Console.Clear Method in C#
The Console.Clear method in C# is used to clear the console buffer and corresponding console window of display information.
Syntax
Following is the syntax −
public static void Clear ();
Example
Let us now see an example before implementing the Console.Clear method −
using System; public class Demo { public static void Main(){ Uri newURI1 = new Uri("https://www.tutorialspoint.com/"); Console.WriteLine("URI = "+newURI1); Console.WriteLine("String representation = "+newURI1.ToString()); Uri newURI2 = new Uri("https://www.tutorialspoint.com/jquery.htm#abcd"); Console.WriteLine("
URI = "+newURI2); Console.WriteLine("String representation = "+newURI2.ToString()); if(newURI1.Equals(newURI2)) Console.WriteLine("
Both the URIs are equal!"); else Console.WriteLine("
Both the URIs aren't equal!"); Uri res = newURI1.MakeRelativeUri(newURI2); Console.WriteLine("Relative uri = "+res); } }
Output
This will produce the following output before using Console.Clear() −
URI = https://www.tutorialspoint.com/ String representation = https://www.tutorialspoint.com/ URI = https://www.tutorialspoint.com/jquery.htm#abcd String representation = https://www.tutorialspoint.com/jquery.htm#abcd Both the URIs aren't equal! Relative uri = jquery.htm#abcd
Example
Let us now see the same example to implement the Console.Clear method −
using System; public class Demo { public static void Main(){ Uri newURI1 = new Uri("https://www.tutorialspoint.com/"); Console.WriteLine("URI = "+newURI1); Console.WriteLine("String representation = "+newURI1.ToString()); Uri newURI2 = new Uri("https://www.tutorialspoint.com/jquery.htm#abcd"); Console.WriteLine("
URI = "+newURI2); Console.WriteLine("String representation = "+newURI2.ToString()); if(newURI1.Equals(newURI2)) Console.WriteLine("
Both the URIs are equal!"); else Console.WriteLine("
Both the URIs aren't equal!"); Uri res = newURI1.MakeRelativeUri(newURI2); Console.WriteLine("Relative uri = "+res); Console.Clear(); Console.WriteLine("Console cleared now!"); } }
Output
This will produce the following output −
Console cleared now!
Advertisements