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 個實例,並加以比較,以判斷它們是否代表相同的值。 address1address2 是相同的,因為 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) 可能包含的部分。 例如,假設 URI http://www.contoso.com/index.htm#search 和 ,方法 Equals 會傳回 true http://user:password@www.contoso.com/index.htm

如果一個 Uri 實例是由 Unicode 主機名稱所組成,且 comparand 參數包含 Uri 具有對等 Punycode 主機名稱的主機名稱所構成的實例或識別碼,則 Equals 只有在啟用國際資源識別碼 (IRI) 和國際化功能變數名稱 (IDN) 支援時,才會傳回 true 。 Punycode 名稱只包含 ASCII 字元,而且開頭一律為前置詞 xn--。

如需 IRI 支援的詳細資訊,請參閱 類別的 Uri 一節。

注意

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

注意

方法 Equals 可以在衍生類別中覆寫;請小心,因為惡意實體可以修改 方法。 除非您知道此實例來自信任的來源,否則不應該使用這個方法來執行安全性檢查。

適用於