Uri.Equality Operator

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

Determines whether two Uri instances have the same value.

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


Public Shared Operator = ( _
    uri1 As Uri, _
    uri2 As Uri _
) As Boolean
public static bool operator ==(
    Uri uri1,
    Uri uri2


Return Value

Type: System.Boolean
A Boolean value that is true if the Uri instances are equivalent; otherwise, false.


This overload uses the Equals method to determine whether the two Uri instances are equivalent. UserInfo and Fragment content is ignored when making this comparison.


This example creates three 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("http://www.contoso.com/index.htm#search")
Dim address2 As Uri = New Uri("http://www.contoso.com/index.htm")
Dim address3 As Uri = New Uri("http://www.contoso.com/index.htm?date=today")

' The first two are equal because the fragment is ignored.
If address1 = address2 Then
  outputBlock.Text &= address1.ToString()
  outputBlock.Text &= " is equal to "
  outputBlock.Text &= address1.ToString()
  outputBlock.Text &= vbCrLf
End If

' The second two are not equal.
If address2 <> address3 Then
  outputBlock.Text &= address2.ToString()
  outputBlock.Text &= " is not equal to "
  outputBlock.Text &= address3.ToString()
  outputBlock.Text &= vbCrLf
End If
// Create some Uris.
Uri address1 = new Uri("http://www.contoso.com/index.htm#search");
Uri address2 = new Uri("http://www.contoso.com/index.htm"); 
Uri address3 = new Uri("http://www.contoso.com/index.htm?date=today"); 

// The first two are equal because the fragment is ignored.
if (address1 == address2) 
   outputBlock.Text += address1.ToString();
   outputBlock.Text += " is equal to ";
   outputBlock.Text += address1.ToString();
   outputBlock.Text += "\n";

// The second two are not equal.
if (address2 != address3)
   outputBlock.Text += address2.ToString();
   outputBlock.Text += " is not equal to ";
   outputBlock.Text += address3.ToString();
   outputBlock.Text += "\n";

Version Information


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


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

See Also