เมธอด Uri.CheckHostName() ใน C# ใช้เพื่อระบุว่าชื่อโฮสต์ที่ระบุเป็นชื่อ DNS ที่ถูกต้องหรือไม่
ไวยากรณ์
ต่อไปนี้เป็นไวยากรณ์ -
public static UriHostNameType CheckHostName (string host_name);
ตัวอย่าง
ให้เราดูตัวอย่างการใช้เมธอด Uri.CheckHostName() -
using System;
public class Demo {
public static void Main(){
string strURI = "http://localhost";
Console.WriteLine("URI = "+strURI);
UriHostNameType res = Uri.CheckHostName(strURI);
Console.WriteLine("Host type = "+res);
}
} ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -
URI = http://localhost Host type = Unknown
ตัวอย่าง
ให้เราดูตัวอย่างอื่นเพื่อใช้เมธอด Uri.CheckHostName() -
using System;
public class Demo {
public static void Main(){
string strURI = "www.tutorialspoint.com";
Console.WriteLine("URI = "+strURI);
UriHostNameType res = Uri.CheckHostName(strURI);
Console.WriteLine("Host type = "+res);
}
} ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -
URI = www.tutorialspoint.com Host type = Dns