Partager via


Uri.Fragment Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets the escaped URI fragment.

Namespace:  System
Assembly:  System (in System.dll)

Syntax

'Declaration
Public ReadOnly Property Fragment As String
public string Fragment { get; }

Property Value

Type: System.String
A String that contains any URI fragment information.

Exceptions

Exception Condition
InvalidOperationException

This property is valid only for an absolute Uri instance.

Remarks

The Fragment property gets any text following a fragment marker (#) in the URI, including the fragment marker itself. Given the URI https://www.contoso.com/index.htm\#main, the Fragment property would return #main.

The Fragment property is not considered in any Equals comparison.

Examples

The following example creates a Uri instance and writes the fragment information to the console.

' Create Uri
Dim uriAddress1 As Uri = New Uri("https://www.contoso.com/index.htm#search")
outputBlock.Text &= uriAddress1.Fragment
outputBlock.Text &= vbCrLf

outputBlock.Text &= "Hash code: "
outputBlock.Text &= uriAddress1.GetHashCode()
outputBlock.Text &= vbCrLf
// Create Uri
Uri uriAddress1 = new Uri("https://www.contoso.com/index.htm#search");
outputBlock.Text += uriAddress1.Fragment;
outputBlock.Text += "\n";

outputBlock.Text += "Hash code: ";
outputBlock.Text += uriAddress1.GetHashCode();
outputBlock.Text += "\n";
// Create Uri
Uri uriAddress = new Uri("https://www.contoso.com/index.htm#search");
Console.WriteLine(uriAddress.Fragment);

Console.WriteLine("Hash code {0}", uriAddress.GetHashCode());

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

See Also

Reference