String.Inequality(String, String) Opérateur
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Détermine si deux chaînes spécifiées ont des valeurs différentes.
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
Première chaîne à comparer, ou null
.
- b
- String
Deuxième chaîne à comparer, ou null
.
true
si la valeur de a
est différente de la valeur de b
; sinon, false
.
L’exemple suivant illustre l’opérateur d’inégalité.
// 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
*/
La Inequality méthode définit l’opération de l’opérateur d’inégalité pour la String classe. Il active le code tel que celui indiqué dans la section exemples.
L' Inequality opérateur appelle à son tour la Equals(String, String) méthode statique, qui effectue une comparaison ordinale (respectant la casse et non-respect de la culture).
Note
le compilateur Visual Basic ne résout pas l’opérateur d’inégalité comme un appel à la Inequality méthode. À la place, l’opérateur d’inégalité encapsule un appel à la Operators.CompareString méthode.
Produit | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |