Phương thức Uri.CheckHostName() trong C# được sử dụng để xác định xem tên máy chủ (hostname) được chỉ định có phải là tên DNS hợp lệ hay không.
Cú pháp
Dưới đây là cú pháp:
public static UriHostNameType CheckHostName (string host_name);
Ví dụ 1
Hãy xem ví dụ sau để triển khai phương thức Uri.CheckHostName():
using System;
public class Demo {
public static void Main(){
string strURI = "https://localhost";
Console.WriteLine("URI = " + strURI);
UriHostNameType res = Uri.CheckHostName(strURI);
Console.WriteLine("Host type = " + res);
}
}
Đầu ra
Chương trình sẽ cho ra kết quả sau:
URI = https://localhost Host type = Unknown
Ví dụ 2
Ví dụ khác triển khai phương thức 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);
}
}
Đầu ra
Chương trình sẽ cho ra kết quả sau:
URI = www.tutorialspoint.com Host type = Dns