C# | Uri.CheckHostName(String) Method
Last Updated :
01 May, 2019
Uri.CheckHostName(String) Method is used to determine whether the specified host name is a valid DNS name or not.
Syntax: public static UriHostNameType CheckHostName (string name);
Here, it takes the host name to validate. This can be an IPv4 or IPv6 address or an Internet host name.
Return Value: This method returns a UriHostNameType which indicates the type of the host name. If the type of the host name cannot be determined or if the host name is null or a zero-length string, this method returns Unknown.
Below programs illustrate the use of Uri.CheckHostName() Method:
Example 1:
using System;
using System.Globalization;
class GFG {
public static void Main()
{
string uri = "www.geeksforgeeks.org" ;
UriHostNameType value = Uri.CheckHostName(uri);
Console.WriteLine( "Host type is: {0}" , value);
}
}
|
Output:
Host type is: Dns
Example 2:
using System;
using System.Globalization;
class GFG {
public static void Main()
{
string uri = "http:// localhost:3000" ;
UriHostNameType value = Uri.CheckHostName(uri);
Console.WriteLine( "Host type is: {0}" , value);
}
}
|
Output:
Host type is: Unknown
Reference:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...