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

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.