Uri.Fragment Egenskap
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Hämtar det förrymda URI-fragmentet, inklusive det inledande #-tecknet om det inte är tomt.
public:
property System::String ^ Fragment { System::String ^ get(); };
public string Fragment { get; }
member this.Fragment : string
Public ReadOnly Property Fragment As String
Egenskapsvärde
URI-fragmentinformation.
Undantag
Den här instansen representerar en relativ URI och den här egenskapen är endast giltig för absoluta URI:er.
Exempel
I följande exempel skapas en Uri instans och fragmentinformationen skrivs till konsolen.
// 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
Kommentarer
Egenskapen Fragment hämtar all text som följer en fragmentmarkör (#) i URI:n, inklusive själva fragmentmarkören. Med tanke på URIhttp://www.contoso.com/index.htm#mainFragment:n returnerar egenskapen #main.
Egenskapen Fragment beaktas inte i någon Equals jämförelse.
Note
Egenskapen innehåller den ledande avgränsare (#), medan URI-specifikationen (RFC 3986) identifierar fragmentet som delen av en URI utan avgränsare.