Uri.IsDefaultPort 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取一个值,该值指示 URI 的端口值是否为此方案的默认值。
public:
property bool IsDefaultPort { bool get(); };
public bool IsDefaultPort { get; }
member this.IsDefaultPort : bool
Public ReadOnly Property IsDefaultPort As Boolean
属性值
true
如果 属性中的 Port 值是此方案的默认端口,则为 ;否则为 false
。
例外
此实例代表一个相对 URI,而此属性仅对绝对 URI 有效。
示例
以下示例创建一个 Uri 实例,并检查它是否使用默认端口。
// 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