CaseInsensitiveHashCodeProvider Classe

Definizione

Attenzione

Please use StringComparer instead.

Attenzione

CaseInsensitiveHashCodeProvider has been deprecated. Use StringComparer instead.

Fornisce un codice hash per un oggetto, utilizzando un algoritmo di hash che ignora la distinzione tra maiuscole e minuscole nelle stringhe.

public ref class CaseInsensitiveHashCodeProvider : System::Collections::IHashCodeProvider
[System.Obsolete("Please use StringComparer instead.")]
public class CaseInsensitiveHashCodeProvider : System.Collections.IHashCodeProvider
[System.Obsolete("CaseInsensitiveHashCodeProvider has been deprecated. Use StringComparer instead.")]
public class CaseInsensitiveHashCodeProvider : System.Collections.IHashCodeProvider
[System.Serializable]
public class CaseInsensitiveHashCodeProvider : System.Collections.IHashCodeProvider
[System.Obsolete("Please use StringComparer instead.")]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class CaseInsensitiveHashCodeProvider : System.Collections.IHashCodeProvider
[<System.Obsolete("Please use StringComparer instead.")>]
type CaseInsensitiveHashCodeProvider = class
    interface IHashCodeProvider
[<System.Obsolete("CaseInsensitiveHashCodeProvider has been deprecated. Use StringComparer instead.")>]
type CaseInsensitiveHashCodeProvider = class
    interface IHashCodeProvider
[<System.Serializable>]
type CaseInsensitiveHashCodeProvider = class
    interface IHashCodeProvider
[<System.Obsolete("Please use StringComparer instead.")>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type CaseInsensitiveHashCodeProvider = class
    interface IHashCodeProvider
Public Class CaseInsensitiveHashCodeProvider
Implements IHashCodeProvider
Ereditarietà
CaseInsensitiveHashCodeProvider
Attributi
Implementazioni

Esempio

Nell'esempio di codice seguente viene creata una tabella hash con distinzione tra maiuscole e minuscole e una tabella hash senza distinzione tra maiuscole e minuscole e viene illustrata la differenza nel comportamento, anche se entrambi contengono gli stessi elementi.

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

*/
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

*/
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

End Class


'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

Commenti

CaseInsensitiveHashCodeProviderimplementa l'interfaccia che supporta confronti senza distinzione tra maiuscole e minuscole nelle stringhe, così come CaseInsensitiveComparer implementa l'interfaccia IHashCodeProviderIComparer che supporta i confronti senza distinzione tra maiuscole e minuscole nelle stringhe.

Importante

Non è consigliabile usare la CaseInsensitiveHashCodeProvider classe per il nuovo sviluppo. È invece consigliabile usare l'oggetto System.StringComparerStringComparer.CurrentCultureIgnoreCaserestituito dalla proprietà , StringComparer.InvariantCultureIgnoreCaseo StringComparer.OrdinalIgnoreCase .

Gli oggetti usati come chiavi da un Hashtable sono necessari per eseguire l'override del Object.GetHashCode metodo (o dell'interfaccia) e del Object.Equals metodo (o dell'interfaccia IHashCodeProviderIComparer). L'implementazione di entrambi i metodi o interfacce deve gestire la riservatezza delle maiuscole e minuscole allo stesso modo; in caso contrario, il Hashtable comportamento potrebbe comportarsi in modo errato. Ad esempio, quando si crea un Hashtableoggetto , è necessario usare questa classe con la CaseInsensitiveComparer classe o qualsiasi implementazione senza distinzione tra maiuscole e minuscole IComparer .

Costruttori

CaseInsensitiveHashCodeProvider()
Obsoleti.
Obsoleti.

Inizializza una nuova istanza della classe CaseInsensitiveHashCodeProvider utilizzando la proprietà CurrentCulture del thread corrente.

CaseInsensitiveHashCodeProvider(CultureInfo)
Obsoleti.
Obsoleti.

Inizializza una nuova istanza della classe CaseInsensitiveHashCodeProvider usando il CultureInfo specificato.

Proprietà

Default
Obsoleti.
Obsoleti.

Ottiene un'istanza di CaseInsensitiveHashCodeProvider associata alla proprietà CurrentCulture del thread corrente e sempre disponibile.

DefaultInvariant
Obsoleti.
Obsoleti.

Ottiene un'istanza di CaseInsensitiveHashCodeProvider associata alla proprietà InvariantCulture e sempre disponibile.

Metodi

Equals(Object)
Obsoleti.
Obsoleti.

Determina se l'oggetto specificato è uguale all'oggetto corrente.

(Ereditato da Object)
GetHashCode()
Obsoleti.
Obsoleti.

Funge da funzione hash predefinita.

(Ereditato da Object)
GetHashCode(Object)
Obsoleti.
Obsoleti.

Viene restituito un codice hash per l'oggetto dato tramite un algoritmo di hash che ignora la distinzione tra maiuscole e minuscole nelle stringhe.

GetType()
Obsoleti.
Obsoleti.

Ottiene l'oggetto Type dell'istanza corrente.

(Ereditato da Object)
MemberwiseClone()
Obsoleti.
Obsoleti.

Crea una copia superficiale dell'oggetto Object corrente.

(Ereditato da Object)
ToString()
Obsoleti.
Obsoleti.

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Si applica a

Vedi anche