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。

返回

Boolean

如果这两个 Uri 实例不相等,则为 true;否则为 false。 如果两者中任意一个参数为 null,则此方法返回 true

示例

此示例从字符串创建三 Uri 个实例,并对其进行比较以确定它们是否表示相同的值。 Address2Address3不一样,因为Address3包含一Address2Query在 . 结果将写入控制台。

// 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 个实例是否不等效。 UserInfoFragment进行此比较时,将忽略内容。

适用于