語言

Uri.Inequality(Uri, Uri) 運算子

定義

判斷兩個 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 op_Inequality : Uri * Uri -> bool
Public Shared Operator != (uri1 As Uri, uri2 As Uri) As Boolean

參數

uri1
Uri

一個可以比較 uri2的 URI。

uri2
Uri

一個可以比較 uri1的 URI。

傳回

true 若 Uri 兩個實例不相等;否則, false。 若任一參數為 null,此方法返回 true。

範例

此範例由字串產生三個 Uri 實例,並比較它們是否代表相同的值。 Address2 與 Address3 不相同,因為 Address3 包含 a Query 且不存在於 Address2。 結果會寫入主控台。

// 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而在做這種比較時,內容卻被忽略了。

適用於