Uri.Fragment 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得逸出 URI 片段,如果不是空的,則包括前置 '#' 字元。
public:
property System::String ^ Fragment { System::String ^ get(); };
public string Fragment { get; }
member this.Fragment : string
Public ReadOnly Property Fragment As String
屬性值
URI 片段資訊。
例外狀況
這個執行個體代表相對的 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
備註
屬性 Fragment 會取得 URI 中片段標記 (#) 之後的任何文字,包括片段標記本身。 假設 URI http://www.contoso.com/index.htm#main
為 ,屬性 Fragment 會傳回#main。
屬性 Fragment 不會在任何比較中 Equals 考慮。