Remarque : cette API est maintenant obsolète. L'alternative non obsolète est StringComparer.
Fournit un code de hachage pour un objet en utilisant un algorithme de hachage qui ignore la casse des chaînes.
System.Collections.CaseInsensitiveHashCodeProvider
Espace de noms : System.Collections
Assembly : mscorlib (dans mscorlib.dll)
<SerializableAttribute> _ <ObsoleteAttribute("Please use StringComparer instead.")> _ <ComVisibleAttribute(True)> _ Public Class CaseInsensitiveHashCodeProvider _ Implements IHashCodeProvider
[SerializableAttribute] [ObsoleteAttribute("Please use StringComparer instead.")] [ComVisibleAttribute(true)] public class CaseInsensitiveHashCodeProvider : IHashCodeProvider
[SerializableAttribute] [ObsoleteAttribute(L"Please use StringComparer instead.")] [ComVisibleAttribute(true)] public ref class CaseInsensitiveHashCodeProvider : IHashCodeProvider
[<SerializableAttribute>] [<ObsoleteAttribute("Please use StringComparer instead.")>] [<ComVisibleAttribute(true)>] type CaseInsensitiveHashCodeProvider = class interface IHashCodeProvider end
Le type CaseInsensitiveHashCodeProvider expose les membres suivants.
| Nom | Description | |
|---|---|---|
|
CaseInsensitiveHashCodeProvider() | Initialise une nouvelle instance de la classe CaseInsensitiveHashCodeProvider à l'aide de Thread.CurrentCulture du thread en cours. |
|
CaseInsensitiveHashCodeProvider(CultureInfo) | Initialise une nouvelle instance de la classe CaseInsensitiveHashCodeProvider à l'aide du System.Globalization.CultureInfo spécifié. |
| Nom | Description | |
|---|---|---|
|
Default | Obtient une instance de CaseInsensitiveHashCodeProvider associée au Thread.CurrentCulture du thread en cours et toujours disponible. |
|
DefaultInvariant | Obtient une instance de CaseInsensitiveHashCodeProvider associée à CultureInfo.InvariantCulture et toujours disponible. |
| Nom | Description | |
|---|---|---|
|
Equals(Object) | Détermine si l'Object spécifié est égal à l'Object en cours. (Hérité de Object.) |
|
Finalize | Autorise un objet à tenter de libérer des ressources et d'exécuter d'autres opérations de netto***ge avant qu'il ne soit récupéré par l'opération garbage collection. (Hérité de Object.) |
|
GetHashCode() | Sert de fonction de hachage pour un type particulier. (Hérité de Object.) |
|
GetHashCode(Object) | Retourne un code de hachage pour un objet donné, en utilisant un algorithme de hachage qui ignore la casse des chaînes. |
|
GetType | Obtient le Type de l'instance actuelle. (Hérité de Object.) |
|
MemberwiseClone | Crée une copie superficielle de l'objet Object actif. (Hérité de Object.) |
|
ToString | Retourne une chaîne qui représente l'objet actuel. (Hérité de Object.) |
CaseInsensitiveHashCodeProvider implémente l'interface IHashCodeProvider prenant en charge les comparaisons sans respecter la casse des chaînes, tout comme CaseInsensitiveComparer implémente l'interface IComparer prenant en charge les comparaisons sans respecter la casse des chaînes.
Les objets utilisés comme clés par Hashtable sont requis pour substituer la méthode Object.GetHashCode (ou l'interface IHashCodeProvider) et la méthode Object.Equals (ou l'interface IComparer). L'implémentation des deux méthodes et interfaces doit gérer le respect de la casse de la même manière ; sinon, le comportement de Hashtable risque d'être incorrect. Par exemple, lors de la création de Hashtable, vous devez utiliser cette classe avec la classe CaseInsensitiveComparer ou toute implémentation de IComparer ne respectant pas la casse.
L'exemple de code suivant crée une table de hachage qui respecte la casse et une autre qui ne la respecte pas, puis illustre leur différence de comportement, même si elles contiennent toutes les deux les mêmes éléments.
Imports System Imports System.Collections Imports System.Globalization Public Class SamplesHashtable Public Shared Sub Main() ' Create a Hashtable using the default hash code provider and the default comparer. Dim myHT1 As New Hashtable() myHT1.Add("FIRST", "Hello") myHT1.Add("SECOND", "World") myHT1.Add("THIRD", "!") ' Create a Hashtable using a case-insensitive code provider and a case-insensitive comparer, ' based on the culture of the current thread. Dim myHT2 As New Hashtable(New CaseInsensitiveHashCodeProvider(), New CaseInsensitiveComparer()) myHT2.Add("FIRST", "Hello") myHT2.Add("SECOND", "World") myHT2.Add("THIRD", "!") ' Create a Hashtable using a case-insensitive code provider and a case-insensitive comparer, ' based on the InvariantCulture. Dim myHT3 As New Hashtable(CaseInsensitiveHashCodeProvider.DefaultInvariant, CaseInsensitiveComparer.DefaultInvariant) myHT3.Add("FIRST", "Hello") myHT3.Add("SECOND", "World") myHT3.Add("THIRD", "!") ' Create a Hashtable using a case-insensitive code provider and a case-insensitive comparer, ' based on the Turkish culture (tr-TR), where "I" is not the uppercase version of "i". Dim myCul As New CultureInfo("tr-TR") Dim myHT4 As New Hashtable(New CaseInsensitiveHashCodeProvider(myCul), New CaseInsensitiveComparer(myCul)) myHT4.Add("FIRST", "Hello") myHT4.Add("SECOND", "World") myHT4.Add("THIRD", "!") ' Search for a key in each hashtable. Console.WriteLine("first is in myHT1: {0}", myHT1.ContainsKey("first")) Console.WriteLine("first is in myHT2: {0}", myHT2.ContainsKey("first")) Console.WriteLine("first is in myHT3: {0}", myHT3.ContainsKey("first")) Console.WriteLine("first is in myHT4: {0}", myHT4.ContainsKey("first")) End Sub 'Main End Class 'SamplesHashtable 'This code produces the following output. Results vary depending on the system's culture settings. ' 'first is in myHT1: False 'first is in myHT2: True 'first is in myHT3: True 'first is in myHT4: False
using System; using System.Collections; using System.Globalization; public class SamplesHashtable { public static void Main() { // Create a Hashtable using the default hash code provider and the default comparer. Hashtable myHT1 = new Hashtable(); myHT1.Add("FIRST", "Hello"); myHT1.Add("SECOND", "World"); myHT1.Add("THIRD", "!"); // Create a Hashtable using a case-insensitive code provider and a case-insensitive comparer, // based on the culture of the current thread. Hashtable myHT2 = new Hashtable( new CaseInsensitiveHashCodeProvider(), new CaseInsensitiveComparer() ); myHT2.Add("FIRST", "Hello"); myHT2.Add("SECOND", "World"); myHT2.Add("THIRD", "!"); // Create a Hashtable using a case-insensitive code provider and a case-insensitive comparer, // based on the InvariantCulture. Hashtable myHT3 = new Hashtable( CaseInsensitiveHashCodeProvider.DefaultInvariant, CaseInsensitiveComparer.DefaultInvariant ); myHT3.Add("FIRST", "Hello"); myHT3.Add("SECOND", "World"); myHT3.Add("THIRD", "!"); // Create a Hashtable using a case-insensitive code provider and a case-insensitive comparer, // based on the Turkish culture (tr-TR), where "I" is not the uppercase version of "i". CultureInfo myCul = new CultureInfo( "tr-TR" ); Hashtable myHT4 = new Hashtable( new CaseInsensitiveHashCodeProvider( myCul ), new CaseInsensitiveComparer( myCul ) ); myHT4.Add("FIRST", "Hello"); myHT4.Add("SECOND", "World"); myHT4.Add("THIRD", "!"); // Search for a key in each hashtable. Console.WriteLine( "first is in myHT1: {0}", myHT1.ContainsKey( "first" ) ); Console.WriteLine( "first is in myHT2: {0}", myHT2.ContainsKey( "first" ) ); Console.WriteLine( "first is in myHT3: {0}", myHT3.ContainsKey( "first" ) ); Console.WriteLine( "first is in myHT4: {0}", myHT4.ContainsKey( "first" ) ); } } /* This code produces the following output. Results vary depending on the system's culture settings. first is in myHT1: False first is in myHT2: True first is in myHT3: True first is in myHT4: False */
using namespace System; using namespace System::Collections; using namespace System::Globalization; int main() { // Create a Hashtable using the default hash code provider and the default comparer. Hashtable^ myHT1 = gcnew Hashtable; myHT1->Add( "FIRST", "Hello" ); myHT1->Add( "SECOND", "World" ); myHT1->Add( "THIRD", "!" ); // Create a Hashtable using a case-insensitive code provider and a case-insensitive comparer, // based on the culture of the current thread. Hashtable^ myHT2 = gcnew Hashtable( gcnew CaseInsensitiveHashCodeProvider,gcnew CaseInsensitiveComparer ); myHT2->Add( "FIRST", "Hello" ); myHT2->Add( "SECOND", "World" ); myHT2->Add( "THIRD", "!" ); // Create a Hashtable using a case-insensitive code provider and a case-insensitive comparer, // based on the InvariantCulture. Hashtable^ myHT3 = gcnew Hashtable( CaseInsensitiveHashCodeProvider::DefaultInvariant,CaseInsensitiveComparer::DefaultInvariant ); myHT3->Add( "FIRST", "Hello" ); myHT3->Add( "SECOND", "World" ); myHT3->Add( "THIRD", "!" ); // Create a Hashtable using a case-insensitive code provider and a case-insensitive comparer, // based on the Turkish culture (tr-TR), where "I" is not the uppercase version of "i". CultureInfo^ myCul = gcnew CultureInfo( "tr-TR" ); Hashtable^ myHT4 = gcnew Hashtable( gcnew CaseInsensitiveHashCodeProvider( myCul ),gcnew CaseInsensitiveComparer( myCul ) ); myHT4->Add( "FIRST", "Hello" ); myHT4->Add( "SECOND", "World" ); myHT4->Add( "THIRD", "!" ); // Search for a key in each hashtable. Console::WriteLine( "first is in myHT1: {0}", myHT1->ContainsKey( "first" ) ); Console::WriteLine( "first is in myHT2: {0}", myHT2->ContainsKey( "first" ) ); Console::WriteLine( "first is in myHT3: {0}", myHT3->ContainsKey( "first" ) ); Console::WriteLine( "first is in myHT4: {0}", myHT4->ContainsKey( "first" ) ); } /* This code produces the following output. Results vary depending on the system's culture settings. first is in myHT1: False first is in myHT2: True first is in myHT3: True first is in myHT4: False */
.NET Framework
Pris en charge dans : 1.1, 1.0Obsolète (avertissement du compilateur) dans 4
Obsolète (avertissement du compilateur) dans 3.5
Obsolète (avertissement du compilateur) dans 3.5 SP1
Obsolète (avertissement du compilateur) dans 3.0
Obsolète (avertissement du compilateur) dans 3.0 SP1
Obsolète (avertissement du compilateur) dans 3.0 SP2
Obsolète (avertissement du compilateur) dans 2.0
Obsolète (avertissement du compilateur) dans 2.0 SP1
Obsolète (avertissement du compilateur) dans 2.0 SP2
.NET Framework Client Profile
Obsolète (avertissement du compilateur) dans 4Obsolète (avertissement du compilateur) dans 3.5 SP1
Windows 7, Windows Vista SP1 ou ultérieur, Windows XP SP3, Windows XP SP2 Édition x64, Windows Server 2008 (installation minimale non prise en charge), Windows Server 2008 R2 (installation minimale prise en charge avec SP1 ou version ultérieure), Windows Server 2003 SP2
Le .NET Framework ne prend pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.