System.Uri.Equals 方法

方法描述

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

语法定义(C# System.Uri.Equals 方法 的用法)

[SecurityPermissionAttribute(SecurityAction.InheritanceDemand, Flags = SecurityPermissionFlag.Infrastructure)]
public override bool Equals(
	Object comparand
)

参数/返回值

参数值/返回值 参数类型/返回类型 参数描述/返回描述
comparand System-Object 与当前实例相比较的 Uri 实例或 URI 标识符。
返回值 System.Boolean 一个 Boolean 值。如果两个实例表示相同的 URI,则该值为 true;否则为 false。

提示和注释

Equals 方法比较这两个实例,而不考虑它们可能包含的用户信息 (UserInfo) 和片段 (Fragment) 部分。 例如,给定 URI http://www.contoso.com/index.htm#search 和 http://user:password@www.contoso.com/index.htm,Equals 方法将返回 true。

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

有关 IRI 支持的更多信息,请参见 Uri 类的“备注”部分。

注意

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

注意

Equals 方法可以在派生类中进行重写;由于恶意实体可能会修改此方法,因此使用时要谨慎。 如果您不知道此实例是否来自受信任的来源,请勿使用此方法来执行安全性检查。

System.Uri.Equals 方法例子

结果将输出到控制台。

// 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");

异常

异常 异常描述

命名空间

namespace: System

程序集: System(在 System.dll 中)

版本信息

.NET Framework 受以下版本支持:4、3.5、3.0、2.0、1.1、1.0 .NET Framework Client Profile 受以下版本支持:4、3.5 SP1 受以下版本支持:

适用平台

Windows 7, Windows Vista SP1 或更高版本, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008(不支持服务器核心), Windows Server 2008 R2(支持 SP1 或更高版本的服务器核心), Windows Server 2003 SP2 .NET Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。