String.op_Inequality 方法

确定两个指定的 String 对象是否具有不同的值。

**命名空间:**System
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
Public Shared Operator <> ( _
    a As String, _
    b As String _
) As Boolean
用法
Dim a As String
Dim b As String
Dim returnValue As Boolean

returnValue = (a <> b)
public static bool operator != (
    string a,
    string b
)
public:
static bool operator != (
    String^ a, 
    String^ b
)
J# 不支持重载运算符。
JScript 支持使用重载运算符,但不支持进行新的声明。

参数

  • a
    String 或 空引用(在 Visual Basic 中为 Nothing)。
  • b
    String 或 空引用(在 Visual Basic 中为 Nothing)。

返回值

如果 a 的值与 b 的值不同,则为 true;否则为 false

备注

使用 Equals 方法实现此运算符,这意味着就引用相等和值相等的组合对比较数进行测试。此运算符执行序号比较。

示例

下面的代码示例演示不等运算符。

' Example for the String Inequality operator.
Imports System
Imports Microsoft.VisualBasic

Module InequalityOp
   
    Sub Main()
        Console.WriteLine( _
            "This example of the String Inequality operator" & _
            vbCrLf & "generates the following output." & vbCrLf)

        CompareAndDisplay("ijkl")
        CompareAndDisplay("ABCD")
        CompareAndDisplay("abcd")
    End Sub 'Main
       
    Sub CompareAndDisplay(Comparand As String)

        Dim Lower As String = "abcd"
          
        Console.WriteLine( _
            """{0}"" <> ""{1}"" ?  {2}", _
            Lower, Comparand, Lower <> Comparand)

    End Sub 'CompareAndDisplay
End Module 'InequalityOp

' This example of the String Inequality operator
' generates the following output.
' 
' "abcd" <> "ijkl" ?  True
' "abcd" <> "ABCD" ?  True
' "abcd" <> "abcd" ?  False
// Example for the String Inequality operator.
using System;

class InequalityOp 
{
    public static void Main() 
    {
        Console.WriteLine( 
            "This example of the String Inequality operator\n" +
            "generates the following output.\n" );

        CompareAndDisplay( "ijkl" );
        CompareAndDisplay( "ABCD" );
        CompareAndDisplay( "abcd" );
    }

    static void CompareAndDisplay( String Comparand )
    {
        String  Lower = "abcd";

        Console.WriteLine( 
            "\"{0}\" != \"{1}\" ?  {2}",
            Lower, Comparand, Lower != Comparand );
    }
}

/*
This example of the String Inequality operator
generates the following output.

"abcd" != "ijkl" ?  True
"abcd" != "ABCD" ?  True
"abcd" != "abcd" ?  False
*/
// Example for the String Inequality operator.
using namespace System;
void CompareAndDisplay( String^ Comparand )
{
   String^ Lower = "abcd";
   Console::WriteLine( "\"{0}\" != \"{1}\" ?  {2}", Lower, Comparand, Lower != Comparand );
}

int main()
{
   Console::WriteLine( "This example of the String Inequality operator\n"
   "generates the following output.\n" );
   CompareAndDisplay( "ijkl" );
   CompareAndDisplay( "ABCD" );
   CompareAndDisplay( "abcd" );
}

/*
This example of the String Inequality operator
generates the following output.

"abcd" != "ijkl" ?  True
"abcd" != "ABCD" ?  True
"abcd" != "abcd" ?  False
*/
// Example for the String Inequality operator.
import System.*;

class InequalityOp
{
    public static void main(String[] args)
    {
        Console.WriteLine(("This example of the String Inequality operator\n" 
            + "generates the following output.\n"));
        CompareAndDisplay("ijkl");
        CompareAndDisplay("ABCD");
        CompareAndDisplay("abcd");
    } //main

    static void CompareAndDisplay(String comparand)
    {
        String lower = "abcd";
        Console.WriteLine("\"{0}\" != \"{1}\" ?  {2}", lower, comparand, 
        System.Convert.ToString(!lower.equals(comparand)));
    } //CompareAndDisplay
} //InequalityOp

/*
This example of the String Inequality operator
generates the following output.

"abcd" != "ijkl" ?  True
"abcd" != "ABCD" ?  True
"abcd" != "abcd" ?  False
*/

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

String 类
String 成员
System 命名空间