The Uri.CheckHostName() method in C# is used to determine whether the specified hostname is a valid DNS name.
Syntax
Following is the syntax −
public static UriHostNameType CheckHostName (string host_name);
Example
Let us now see an example to implement the Uri.CheckHostName() method −
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);
}
}Output
This will produce the following output −
URI = http://localhost Host type = Unknown
Example
Let us now see another example to implement the Uri.CheckHostName() method −
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);
}
}Output
This will produce the following output −
URI = www.tutorialspoint.com Host type = Dns