String.Equality(String, String) Opérateur
Définition
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 la même valeur.
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 ( = ) : string * string -> bool
Public Shared Operator == (a As String, b As String) As Boolean
Paramètres
- a
- String
Première chaîne à comparer, ou null.
- b
- String
Deuxième chaîne à comparer, ou null.
Retours
true si la valeur de a est identique à la valeur de b; sinon, false.
Exemples
L’exemple suivant illustre l’opérateur d’égalité.
// Example for the String Equality operator.
using System;
class EqualityOp
{
public static void Main()
{
Console.WriteLine(
"This example of the String Equality 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 Equality operator
generates the following output.
"abcd" == "ijkl" ? False
"abcd" == "ABCD" ? False
"abcd" == "abcd" ? True
*/
// Example for the String Equality operator.
printfn "This example of the String Equality 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 Equality operator
generates the following output.
"abcd" == "ijkl" ? False
"abcd" == "ABCD" ? False
"abcd" == "abcd" ? True
*)
Remarques
La Equality méthode définit l’opération de l’opérateur d’égalité pour la String classe. Il active le code tel que celui indiqué dans la section Exemple. L’opérateur appelle à son tour la méthode statique Equals(String, String) , qui effectue une comparaison ordinale (sensible à la casse et non sensible à la culture).
Note
Le compilateur Visual Basic ne résout pas l’opérateur d’égalité en tant qu’appel à la méthode Equality. Au lieu de cela, l’opérateur d’égalité encapsule un appel à la Operators.CompareString méthode.