Home » C#

C# | Uri.IsDefaultPort Property with Example

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

Uri.IsDefaultPort Property

Uri.IsDefaultPort Property is instance property of Uri class which used to check that specified port is default port or not. This property returns a boolean value. If the specified port of Uri is default port then it returns true otherwise it returns false. This property may generate System.InvalidOperationException exception.

Syntax:

    public bool IsDefaultPort { get; }

Return value:

The return type of this property is Boolean, it returns a Boolean value that is true if the value in the Port property is the default port for this scheme; otherwise, false.

Example to demonstrate example of Uri.IsDefaultPort Property

using System;

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

        domainUri = new Uri("https://www.includehelp.com:8082");
        domainUri1 = new Uri("https://www.includehelp.com:80");

        if (domainUri.IsDefaultPort)
            Console.WriteLine("Given port is default port");
        else
            Console.WriteLine("Given port is not default port");


        if (domainUri1.IsDefaultPort)
            Console.WriteLine("Given port is default port");
        else
            Console.WriteLine("Given port is not default port");
    }
}

Output

Given port is not default port
Given port is not default port

In the above program, we created an object of Uri class initialized with website name with port number and here we checked given specified port number is default port or not using IsDefaultPort property of Uri class.

Reference: Uri.IsDefaultPort Property



Comments and Discussions!

Load comments ↻





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