String.Inequality(String, String) 操作员
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
确定两个指定的字符串是否具有不同的值。
public:
static bool operator !=(System::String ^ a, System::String ^ b);
public static bool operator != (string a, string b);
public static bool operator != (string? a, string? b);
static member op_Inequality : string * string -> bool
Public Shared Operator != (a As String, b As String) As Boolean
参数
- a
- String
要比较的第一个字符串,或 null
。
- b
- String
要比较的第二个字符串,或 null
。
返回
如果 true
的值与 a
的值不同,则为 b
;否则为 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.
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.
printfn "This example of the String Inequality operator\ngenerates the following output.\n"
let compareAndDisplay comparand =
let lower = "abcd"
printfn $"\"%s{lower}\" <> \"%s{comparand}\" ? {lower <> comparand}"
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
*)
注解
方法 Inequality 定义 类的不相等运算符的操作 String 。 它启用示例部分所示的代码。
运算符 Inequality 依次调用静态 Equals(String, String) 方法,该方法执行序号 (区分大小写和不区分区域性的) 比较。
注意
Visual Basic 编译器不会将不相等运算符解析为对 方法的 Inequality 调用。 相反,不相等运算符包装对 方法的 Operators.CompareString 调用。