Uri.IsDefaultPort Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets a value that indicates whether the port value of the URI is the default for this scheme.
public:
property bool IsDefaultPort { bool get(); };
public bool IsDefaultPort { get; }
member this.IsDefaultPort : bool
Public ReadOnly Property IsDefaultPort As Boolean
Property Value
true
if the value in the Port property is the default port for this scheme; otherwise, false
.
Exceptions
This instance represents a relative URI, and this property is valid only for absolute URIs.
Examples
The following example creates a Uri instance and checks whether it uses the default port.
// Create Uri
Uri^ uriAddress = gcnew Uri( "http://www.contoso.com/index.htm#search" );
Console::WriteLine( uriAddress->Fragment );
Console::WriteLine( "Uri {0} the default port ", uriAddress->IsDefaultPort ? (String^)"uses" : "does not use" );
Console::WriteLine( "The path of this Uri is {0}", uriAddress->GetLeftPart( UriPartial::Path ) );
Console::WriteLine( "Hash code {0}", uriAddress->GetHashCode() );
// The example displays output similar to the following:
// #search
// Uri uses the default port
// The path of this Uri is http://www.contoso.com/index.htm
// Hash code -988419291
// Create Uri
Uri uriAddress = new Uri("http://www.contoso.com/index.htm#search");
Console.WriteLine(uriAddress.Fragment);
Console.WriteLine("Uri {0} the default port ", uriAddress.IsDefaultPort ? "uses" : "does not use");
Console.WriteLine("The path of this Uri is {0}", uriAddress.GetLeftPart(UriPartial.Path));
Console.WriteLine("Hash code {0}", uriAddress.GetHashCode());
// The example displays output similar to the following:
// #search
// Uri uses the default port
// The path of this Uri is http://www.contoso.com/index.htm
// Hash code -988419291
// Create Uri
let uriAddress = Uri "http://www.contoso.com/index.htm#search"
printfn $"{uriAddress.Fragment}"
printfn $"""Uri {if uriAddress.IsDefaultPort then "uses" else "does not use"} the default port """
printfn $"The path of this Uri is {uriAddress.GetLeftPart UriPartial.Path}"
printfn $"Hash code {uriAddress.GetHashCode()}"
// The example displays output similar to the following:
// #search
// Uri uses the default port
// The path of this Uri is http://www.contoso.com/index.htm
// Hash code -988419291
' Create Uri
Dim uriAddress As New Uri("http://www.contoso.com/index.htm#search")
Console.WriteLine(uriAddress.Fragment)
Console.WriteLine("Uri {0} the default port ", If(uriAddress.IsDefaultPort, "uses", "does not use"))
Console.WriteLine("The path of this Uri is {0}", uriAddress.GetLeftPart(UriPartial.Path))
Console.WriteLine("Hash code {0}", uriAddress.GetHashCode())
' The example displays output similar to the following:
' #search
' Uri uses the default port
' The path of this Uri is http://www.contoso.com/index.htm
' Hash code -988419291