Compartilhar via


Uri.Equals Method

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

Compares two Uri instances for equality.

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

Syntax

'Declaration
<SecuritySafeCriticalAttribute> _
Public Overrides Function Equals ( _
    comparand As Object _
) As Boolean
[SecuritySafeCriticalAttribute]
public override bool Equals(
    Object comparand
)

Parameters

  • comparand
    Type: System.Object
    The Uri instance or a URI identifier to compare with the current instance.

Return Value

Type: System.Boolean
A Boolean value that is true if the two instances represent the same URI; otherwise, false.

Remarks

The Equals method compares the two instances without regard to user information (UserInfo) and fragment (Fragment) parts that they might contain. For example, given the URIs https://www.contoso.com/index.htm\#search and https://user:password@www.contoso.com/index.htm, the Equals method would return true.

NoteNote:

The Equals method can be overridden in a derived class; use caution as a malicious entity could modify the method. You should not use this method to perform security checks unless you know that this instance came from a trusted source.

Examples

This example creates two Uri instances from strings and compares them to determine whether they represent the same value. address1 and address2 are the same because the Fragment portion is ignored for this comparison. The outcome is written to the console.

' Create some Uris.
Dim address1 As Uri = New Uri("https://www.contoso.com/index.htm#search")
Dim address2 As Uri = New Uri("https://www.contoso.com/index.htm")
If address1.Equals(address2) Then 
  outputBlock.Text &= "The two addresses are equal"
  outputBlock.Text &= vbCrLf
Else
  outputBlock.Text &= "The two addresses are equal"
  outputBlock.Text &= vbCrLf
End If
// Create some Uris.
Uri address1 = new Uri("https://www.contoso.com/index.htm#search");
Uri address2 = new Uri("https://www.contoso.com/index.htm"); 
if (address1.Equals(address2))
    outputBlock.Text += "The two addresses are equal\n";
else
    outputBlock.Text += "The two addresses are not equal\n";
// Create some Uris.
Uri address1 = new Uri("https://www.contoso.com/index.htm#search");
Uri address2 = new Uri("https://www.contoso.com/index.htm"); 
if (address1.Equals(address2))
    Console.WriteLine("The two addresses are equal");
else
    Console.WriteLine("The two addresses are not equal");

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