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

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.