Uri.Fragment Property

Definition

取得逸出的 URI 片段。Gets the escaped URI fragment.

public:
 property System::String ^ Fragment { System::String ^ get(); };
public string Fragment { get; }
member this.Fragment : string
Public ReadOnly Property Fragment As String

Property Value

String

String,包含任何 URI 片段資訊。A String that contains any URI fragment information.

Exceptions

這個執行個體代表相對的 URI,而這個屬性只適用於絕對 URI。This instance represents a relative URI, and this property is valid only for absolute URIs.

Examples

下列範例會建立 Uri 實例,並將片段資訊寫入主控台。The following example creates a Uri instance and writes the fragment information to the console.

// 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 the following output:
//        #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 the following output:
//        #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 the following output:
'        #search
'        Uri uses the default port
'        The path of this Uri is http://www.contoso.com/index.htm
'        Hash code -988419291

Remarks

Fragment 屬性會取得 URI 中片段標記(#)後面的任何文字,包括片段標記本身。The Fragment property gets any text following a fragment marker (#) in the URI, including the fragment marker itself. 假設 URI http://www.contoso.com/index.htm#mainFragment 屬性會傳回 #main。Given the URI http://www.contoso.com/index.htm#main, the Fragment property would return #main.

在任何 Equals 比較中,不會考慮 Fragment 屬性。The Fragment property is not considered in any Equals comparison.

Applies to