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"

注解

方法对两个实例进行比较, 而不考虑它们UserInfo可能包含的用户Fragment信息 () 和片段 () 部分。 EqualsThe Equals method compares the two instances without regard to user information (UserInfo) and fragment (Fragment) parts that they might contain. 例如, 给定http://www.contoso.com/index.htm#search uri 和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 主机名的主机名构成的实例或标识符, 则返回true Equals仅当启用了国际资源标识符 (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.

适用于