Uri.Equals(Object) 方法

定义

比较两个 Uri 实例是否相等。

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 标识符。

返回

Boolean

如果两个实例表示相同的 URI,则该值为 true;否则为 false

示例

此示例从字符串创建两个 Uri 实例,并对其进行比较以确定它们是否表示相同的值。 address1 并且 address2 是相同的,因为此比较中忽略了 Fragment 该部分。 结果将写入控制台。

// 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.
let address1 = Uri "http://www.contoso.com/index.htm#search"
let address2 = Uri "http://www.contoso.com/index.htm"
if address1.Equals address2 then
    printfn "The two addresses are equal"
else
    printfn "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) 可能包含的部分。 例如,给定 URIhttp://www.contoso.com/index.htm#search,该方法http://user:password@www.contoso.com/index.htmEquals将返回true

如果一个 Uri 实例由 Unicode 主机名组成,并且 comparand 参数包含一个 Uri 实例或标识符,该实例由具有等效的 Punycode 主机名的主机名构成,则 Equals 仅当启用了国际资源标识符 (IRI) 和国际化域名 (IDN) 支持时才返回 true 。 Punycode 名称只包含 ASCII 字符,并且始终以 xn-- 前缀开头。

有关 IRI 支持的详细信息,请参阅类的 Uri “备注”部分。

备注

在.NET Framework版本 1.0 和 1.1 中,也会忽略该Query版本。

备注

Equals可以在派生类中重写该方法;谨慎,因为恶意实体可以修改该方法。 除非知道此实例来自受信任的源,否则不应使用此方法执行安全检查。

适用于