Home » C#

C# | Uri.CheckHostName() Method with Example

Uri.CheckHostName() Method: Here, we are going to learn about the CheckHostName() method of Uri class with example in C#.
Submitted by Nidhi, on March 28, 2020

Uri.CheckHostName() Method

Uri.CheckHostName() method is a static method that returns the object of UriHostNameType enum than we need to compare returned enum object with UriHostNameType.Dns. If both are equal then the condition will be true otherwise it will be false.

Syntax:

    UriHostNameType Uri.CheckHostName(string Hostname);

Parameter(s):

  • string Hostname – represents the hostname to be checked, whether it is valid or not.

Return value:

The return type of this method is UriHostNameType, it returns an object of UriHostNameType enum, that is compared with UriHostNameType.Dns to check DNS is valid or not.

Example to demonstrate example of Uri.CheckHostName() method

using System;

class UriExample
{
    //Entry point of Program
    static public void Main()
    {
        UriHostNameType hostNameType;
        
        hostNameType =Uri.CheckHostName("www.includehelp.com");
        if (hostNameType == UriHostNameType.Dns)
        {
            Console.WriteLine("It is valid DNS");
        }
        else
        {
            Console.WriteLine("It is not valid DNS");
        }

        hostNameType = Uri.CheckHostName("www.includehelp!com");
        if (hostNameType == UriHostNameType.Dns)
        {
            Console.WriteLine("It is valid DNS");
        }
        else
        {
            Console.WriteLine("It is not valid DNS");
        }
    }
}

Output

It is valid DNS
It is not valid DNS


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.