This documentation is archived and is not being maintained.

Uri.Equality Operator

Determines whether two Uri instances have the same value.

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

public static bool operator ==(
	Uri uri1,
	Uri uri2


Type: System.Uri

A Uri instance to compare with uri2.

Type: System.Uri

A Uri instance to compare with uri1.

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.
Uri address1 = new Uri("");
Uri address2 = new Uri(""); 
Uri address3 = new Uri(""); 

// The first two are equal because the fragment is ignored. 
if (address1 == address2)
    Console.WriteLine("{0} is equal to {1}", address1.ToString(), address2.ToString());

// The second two are not equal. 
if (address2 != address3)
    Console.WriteLine("{0} is not equal to {1}", address2.ToString(), address3.ToString());
// Create some Uris.
Uri* address1 = new Uri(S"");
Uri* address2 = new Uri(S""); 
Uri* address3 = new Uri(S""); 

// The first two are equal because the fragment is ignored.
if (address1 == address2)
   Console::WriteLine(S"{0} is equal to {1}", address1, address2);

// The second two are not equal.
if (address2 != address3)
   Console::WriteLine(S"{0} is not equal to {1}", address2, address3);

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0

.NET Compact Framework

Supported in: 3.5, 2.0

XNA Framework

Supported in: 3.0, 2.0, 1.0