Phương thức Console.Clear trong C # được sử dụng để xóa bộ đệm bảng điều khiển và cửa sổ thông tin hiển thị tương ứng của bảng điều khiển.
Cú pháp
Sau đây là cú pháp -
public static void Clear ();
Ví dụ
Bây giờ chúng ta hãy xem một ví dụ trước khi triển khai phương thức Console.Clear -
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("\nURI = "+newURI2);
Console.WriteLine("String representation = "+newURI2.ToString());
if(newURI1.Equals(newURI2))
Console.WriteLine("\nBoth the URIs are equal!");
else
Console.WriteLine("\nBoth the URIs aren't equal!");
Uri res = newURI1.MakeRelativeUri(newURI2);
Console.WriteLine("Relative uri = "+res);
}
} Đầu ra
Điều này sẽ tạo ra kết quả sau trước khi sử dụng 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
Ví dụ
Bây giờ chúng ta hãy xem cùng một ví dụ để triển khai phương thức Console.Clear -
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("\nURI = "+newURI2);
Console.WriteLine("String representation = "+newURI2.ToString());
if(newURI1.Equals(newURI2))
Console.WriteLine("\nBoth the URIs are equal!");
else
Console.WriteLine("\nBoth the URIs aren't equal!");
Uri res = newURI1.MakeRelativeUri(newURI2);
Console.WriteLine("Relative uri = "+res);
Console.Clear();
Console.WriteLine("Console cleared now!");
}
} Đầu ra
Điều này sẽ tạo ra kết quả sau -
Console cleared now!