Home » C#

C# | Uri.Host Property with Example

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

Uri.Host Property

Uri.Host Property is the instance property of Uri class which used to get host components from URI. This property returns a string value. This property may generate System.InvalidOperationException exception.

Syntax:

    public string Host { get; }

Return value:

The return type of this property is string, it returns a string that contains the host name. This is usually the DNS host name or IP address of the server.

Example to demonstrate example of Uri.Host 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("Host Component: " + newUri.Host);
    }
}

Output

Host Component: www.includehelp.com

In the above program, we created an object of Uri class initialized with the website name with port number and we got host component from Uri.

Reference: Uri.Host Property




Comments and Discussions!

Load comments ↻






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