Export (0) Print
Expand All

Uri.Equals Method (Object)

Compares two Uri instances for equality.

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

public override bool Equals (
	Object comparand
)
public boolean Equals (
	Object comparand
)
public override function Equals (
	comparand : Object
) : boolean

Parameters

comparand

The Uri instance or a URI identifier to compare with the current instance.

Return Value

true if the two instances represent the same URI; otherwise, false.

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 http://www.contoso.com/index.htm#search and http://user:password@www.contoso.com/index.htm, the Equals method would return true.

NoteNote

In the .NET Framework versions 1.0 and 1.1, the Query is also ignored.

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.

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.
Uri address1 = new Uri("http://www.contoso.com/index.htm#search");
Uri address2 = new Uri("http://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");

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft