Uri.Fragment Właściwość

Definicja

Pobiera usunięty fragment identyfikatora URI, w tym wiodący znak "#", jeśli nie jest pusty.

C#
public string Fragment { get; }

Wartość właściwości

Informacje o fragmentach identyfikatora URI.

Wyjątki

To wystąpienie reprezentuje względny identyfikator URI, a ta właściwość jest prawidłowa tylko dla bezwzględnych identyfikatorów URI.

Przykłady

Poniższy przykład tworzy Uri wystąpienie i zapisuje informacje o fragmentach w konsoli programu .

C#
// 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

Uwagi

Właściwość Fragment pobiera dowolny tekst po znaczniku fragmentu (#) w identyfikatorze URI, w tym sam znacznik fragmentu. Biorąc pod uwagę identyfikator URI http://www.contoso.com/index.htm#main, Fragment właściwość zwróci #main.

Właściwość nie jest brana Fragment pod uwagę w żadnym Equals porównaniu.

Dotyczy

Produkt Wersje
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0