Uri.CheckHostName(String) Method in C#


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

Updated on: 13-Nov-2019

214 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements