เมธอด Console.Clear ใน C# ใช้เพื่อล้างบัฟเฟอร์คอนโซลและหน้าต่างคอนโซลที่เกี่ยวข้องของข้อมูลที่แสดง
ไวยากรณ์
ต่อไปนี้เป็นไวยากรณ์ -
public static void Clear ();
ตัวอย่าง
ให้เรามาดูตัวอย่างก่อนใช้เมธอด 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() -
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
ตัวอย่าง
ให้เราดูตัวอย่างเดียวกันเพื่อนำเมธอด 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!");
}
} ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -
Console cleared now!