C# | Uri.CheckHostName(String) Method

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to demonstrate the
// Uri.CheckHostName(string) Method
using System;
using System.Globalization;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
        // Declaring and initializing uri
        string uri = "www.geeksforgeeks.org";
  
        // using CheckHostName() method
        UriHostNameType value = Uri.CheckHostName(uri);
  
        // Displaying the result
        Console.WriteLine("Host type is: {0}", value);
    }
}

chevron_right


Output:

Host type is: Dns

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to demonstrate the
// Uri.CheckHostName(string) Method
using System;
using System.Globalization;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
        // Declaring and initializing uri
        string uri = "http:// localhost:3000";
  
        // using CheckHostName() method
        UriHostNameType value = Uri.CheckHostName(uri);
  
        // Displaying the result
        Console.WriteLine("Host type is: {0}", value);
    }
}

chevron_right


Output:

Host type is: Unknown

Reference:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.