Uri.Equals 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
多載
| 名稱 | Description |
|---|---|
| Equals(Object) |
比較兩個 Uri 實例以表示相等。 |
| Equals(Uri) |
比較兩個 Uri 實例以表示相等。 |
Equals(Object)
- 來源:
- Uri.cs
- 來源:
- Uri.cs
- 來源:
- Uri.cs
- 來源:
- Uri.cs
- 來源:
- Uri.cs
比較兩個 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 識別碼來與當前實例比較。
傳回
true若兩個實例代表相同的 URI;否則,。 false
範例
此範例由字串產生兩個 Uri 實例,並比較它們是否代表相同的值。
address1 且 address2 相同,因為此比較忽略了該 Fragment 部分。 結果會寫入主控台。
// 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 和 ,該http://user:password@www.contoso.com/index.htm方法將回傳 Equalstrue。
若一個 Uri 實例以 Unicode 主機名稱成立,且 comparand 參數包含 Uri 以主機名稱為 Punycode 主機名稱的實例或識別碼,則 Equals 僅在啟用國際資源識別碼(IRI)及國際化網域名稱(IDN)支援時才回傳 true 。 Punycode 名稱只包含 ASCII 字元,且一律以 xn-- 前置詞開頭。
欲了解更多關於IRI支援的資訊,請參閱該 Uri 課程備註區。
Note
在 .NET Framework 1.0 和 1.1 版本中,Query 也被忽略。
Note
該 Equals 方法可在衍生類別中被覆寫;但請謹慎,因為惡意實體可能會修改該方法。 除非你確定這個實例來自可信來源,否則不應該用這種方法來進行安全檢查。