Прочетете на английски Редактиране

Споделяне чрез


Uri.Equals Method

Definition

Overloads

Equals(Object)

Compares two Uri instances for equality.

Equals(Uri)

Compares two Uri instances for equality.

Equals(Object)

Source:
Uri.cs
Source:
Uri.cs
Source:
Uri.cs

Compares two Uri instances for equality.

C#
public override bool Equals(object comparand);
C#
public override bool Equals(object? comparand);

Parameters

comparand
Object

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

Returns

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

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.

C#
// 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");
// Will output "The two addresses are equal"

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

If one Uri instance is formed with a Unicode host name and comparand parameter contains a Uri instance or identifier that is formed with a host name that has the equivalent Punycode host name, then Equals returns true only if International Resource Identifier (IRI) and Internationalized Domain Name (IDN) support are enabled. Punycode names contain only ASCII characters and always start with the xn-- prefix.

For more information on IRI support, see the Remarks section for the Uri class.

Бележка

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

Бележка

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.

Applies to

.NET 10 и други версии
Продукт Версии
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

Equals(Uri)

Compares two Uri instances for equality.

C#
public bool Equals(Uri? other);

Parameters

other
Uri

The Uri to compare to this instance.

Returns

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

Implements

Applies to

.NET 10 и .NET 9
Продукт Версии
.NET 9, 10