Uri.Equality(Uri, Uri) 運算子
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
判斷兩個 Uri 執行個體的值是否相同。
public:
static bool operator ==(Uri ^ uri1, Uri ^ uri2);
public static bool operator == (Uri uri1, Uri uri2);
public static bool operator == (Uri? uri1, Uri? uri2);
static member ( = ) : Uri * Uri -> bool
Public Shared Operator == (uri1 As Uri, uri2 As Uri) As Boolean
參數
- uri1
- Uri
要與 uri2
比較的 URI。
- uri2
- Uri
要與 uri1
比較的 URI。
傳回
如果 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" );
Uri^ address3 = gcnew Uri( "http://www.contoso.com/index.htm?date=today" );
// The first two are equal because the fragment is ignored.
if ( address1 == address2 )
Console::WriteLine( "{0} is equal to {1}", address1, address2 );
// The second two are not equal.
if ( address2 != address3 )
Console::WriteLine( "{0} is not equal to {1}", address2, address3 );
// Create some Uris.
Uri address1 = new Uri("http://www.contoso.com/index.htm#search");
Uri address2 = new Uri("http://www.contoso.com/index.htm");
Uri address3 = new Uri("http://www.contoso.com/index.htm?date=today");
// The first two are equal because the fragment is ignored.
if (address1 == address2)
Console.WriteLine("{0} is equal to {1}", address1.ToString(), address2.ToString());
// The second two are not equal.
if (address2 != address3)
Console.WriteLine("{0} is not equal to {1}", address2.ToString(), address3.ToString());
// Create some Uris.
let address1 = Uri "http://www.contoso.com/index.htm#search"
let address2 = Uri "http://www.contoso.com/index.htm"
let address3 = Uri "http://www.contoso.com/index.htm?date=today"
// The first two are equal because the fragment is ignored.
if address1 = address2 then
printfn $"{address1} is equal to {address2}"
// The second two are not equal.
if address2 <> address3 then
printfn $"{address2} is not equal to {address3}"
' 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")
Dim address3 As New Uri("http://www.contoso.com/index.htm?date=today")
' The first two are equal because the fragment is ignored.
If address1 = address2 Then
Console.WriteLine("{0} is equal to {1}", address1.ToString(), address2.ToString())
End If
' The second two are not equal.
If address2 <> address3 Then
Console.WriteLine("{0} is not equal to {1}", address2.ToString(), address3.ToString())
End If
備註
這個多載會 Equals 使用 方法來判斷兩 Uri 個實例是否相等。 UserInfo 進行這項比較時,會忽略 和 Fragment 內容。