Phương thức Uri.CheckHostName () trong C # được sử dụng để xác định xem tên máy chủ được chỉ định có phải là tên DNS hợp lệ hay không.
Cú pháp
Sau đây là cú pháp -
public static UriHostNameType CheckHostName (string host_name);
Ví dụ
Bây giờ chúng ta hãy xem một ví dụ để triển khai phương thức 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);
}
} Đầu ra
Điều này sẽ tạo ra kết quả sau -
URI = http://localhost Host type = Unknown
Ví dụ
Bây giờ chúng ta hãy xem một 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
Điều này sẽ tạo ra kết quả sau -
URI = www.tutorialspoint.com Host type = Dns