Uri.Equals(Object) 方法
定义
public:
override bool Equals(System::Object ^ comparand);
public override bool Equals (object comparand);
public override bool Equals (object? comparand);
override this.Equals : obj -> bool
Public Overrides Function Equals (comparand As Object) As Boolean
参数
- comparand
- Object
与当前实例相比较的 URI 或 URI 标识符。The URI or a URI identifier to compare with the current instance.
返回
如果两个实例表示相同的 URI,则该值为 true;否则为 false。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. address1 和 address2 都是相同的,因为 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. 例如,给定 Uri http://www.contoso.com/index.htm#search 和 http://user:password@www.contoso.com/index.htm ,则 Equals 方法将返回 true 。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.
如果一个 Uri 实例的格式为 Unicode 主机名,而 comparand 参数包含 Uri 使用具有等效的 Punycode 主机名的主机名构成的实例或标识符,则 Equals true 仅 (当) 和国际化域名 (启用了 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.