Home » C#

C# | Uri.HostNameType Property with Example

Uri.HostNameType Property: Here, we are going to learn about the HostNameType Property of Uri class with example in C#.
Submitted by Nidhi, on March 28, 2020

Uri.HostNameType Property

Uri.HostNameType Property is the instance property of Uri class which used to get the type of hostname specified in the given URI. This property returns a string value. This property may generate System.InvalidOperationException exception.

Syntax:

    public UriHostNameType HostNameType { get; }

Return value:

The return type of this property is UriHostNameType, it returns a member of the UriHostNameType enumeration.

Example to demonstrate example of Uri.HostNameType Property

using System;

class UriExample
{
    //Entry point of Program
    static public void Main()
    {
        Uri domainUri;
        Uri newUri;

        domainUri = new Uri("https://www.includehelp.com:8082");
        newUri = new Uri(domainUri, "CPrograms.html?Top=10");

        System.Console.WriteLine("HostName Type: " + newUri.HostNameType);
    }
}

Output

HostName Type: Dns

In the above program, we created an object of Uri class initialized with the website name with port number and we got the type of hostname from Uri using HostNameType property.

Reference: Uri.HostNameType Property



Comments and Discussions!

Load comments ↻





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