Uri.Equals(Object) Uri.Equals(Object) Uri.Equals(Object) Uri.Equals(Object) Method

定义

比较两个 Uri 实例是否相等。Compares two Uri instances for equality.

public:
 override bool Equals(System::Object ^ comparand);
public override bool Equals (object comparand);
override this.Equals : obj -> bool
Public Overrides Function Equals (comparand As Object) As Boolean

参数

comparand
Object Object Object Object

与当前实例相比较的 Uri 实例或 URI 标识符。The Uri instance or a URI identifier to compare with the current instance.

返回

一个 Boolean 值。如果两个实例表示相同的 URI,则该值为 true;否则为 falseA Boolean value that is true if the two instances represent the same URI; otherwise, false.

示例

此示例创建两个Uri实例从字符串并将它们,以确定它们是否表示相同的值进行比较。This example creates two Uri instances from strings and compares them to determine whether they represent the same value. address1address2是相同,因为Fragment部分此比较将被忽略。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 = gcnew Uri( "http://www.contoso.com/index.htm#search" );
Uri^ address2 = gcnew 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"
// 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"
' Create some Uris.
Dim address1 As New Uri("http://www.contoso.com/index.htm#search")
Dim address2 As New Uri("http://www.contoso.com/index.htm")
If address1.Equals(address2) Then
    Console.WriteLine("The two addresses are equal")
Else
    Console.WriteLine("The two addresses are not equal")
End If
' Will output "The two addresses are equal"

注解

Equals方法比较两个实例而不考虑用户信息 (UserInfo) 和片段 (Fragment) 可能包含的部件。The Equals method compares the two instances without regard to user information (UserInfo) and fragment (Fragment) parts that they might contain. 例如,给定 Urihttp://www.contoso.com/index.htm#search并http://user:password@www.contoso.com/index.htm,则Equals方法将返回trueFor 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.

如果一个Uri实例格式使用 Unicode 主机名和comparand参数包含Uri实例或使用有等效的 Punycode 主机名,则主机名格式正确的标识符Equals返回true启用仅在国际资源标识符 (IRI) 和国际化域名 (IDN) 支持。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 名称只包含 ASCII 字符,并且始终以 xn-- 前缀开头。Punycode names contain only ASCII characters and always start with the xn-- prefix.

IRI 支持的详细信息,请参阅备注部分Uri类。For more information on IRI support, see the Remarks section for the Uri class.

备注

在.NET framework 1.0 和 1.1,Query也被忽略。In the .NET Framework versions 1.0 and 1.1, the Query is also ignored.

备注

Equals可以在派生类中重写方法; 的恶意实体可以修改该方法,请谨慎使用。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.

安全性

SecurityPermission
若要防止部分受信任的代码派生自Urito prevent partially trusted code from deriving from Uri. 关联枚举:InfrastructureAssociated enumeration: Infrastructure.

适用于