CaseInsensitiveHashCodeProvider Klasse

Definition

Warnung

Diese API ist jetzt veraltet.

Stellt einen Hashcode für ein Objekt bereit, wobei im verwendeten Hashalgorithmus die Groß- und Kleinschreibung von Zeichenfolgen ignoriert wird.Supplies a hash code for an object, using a hashing algorithm that ignores the case of strings.

public ref class CaseInsensitiveHashCodeProvider : System::Collections::IHashCodeProvider
public class CaseInsensitiveHashCodeProvider : System.Collections.IHashCodeProvider
[System.Obsolete("Please 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
type CaseInsensitiveHashCodeProvider = class
    interface IHashCodeProvider
[<System.Obsolete("Please 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
Vererbung
CaseInsensitiveHashCodeProvider
Attribute
Implementiert

Beispiele

Im folgenden Codebeispiel wird eine Hash Tabelle mit Berücksichtigung von Groß-und Kleinschreibung erstellt, und es wird die Groß-/Kleinschreibung beachtet, und die Unterschiede im Verhalten werden veranschaulicht, auch wenn beide dieselben Elemente enthalten.The following code example creates a case-sensitive hash table and a case-insensitive hash table and demonstrates the difference in their behavior, even if both contain the same elements.

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

Hinweise

CaseInsensitiveHashCodeProviderimplementiert die IHashCodeProvider -Schnittstelle, die Vergleiche ohne Berücksichtigung der Groß-/Kleinschreibung für Zeichen folgen unterstützt CaseInsensitiveComparer IComparerCaseInsensitiveHashCodeProvider implements the IHashCodeProvider interface supporting case-insensitive comparisons on strings, just as CaseInsensitiveComparer implements the IComparer interface supporting case-insensitive comparisons on strings.

Wichtig

Es wird nicht empfohlen, die- CaseInsensitiveHashCodeProvider Klasse für die neue Entwicklung zu verwenden.We don't recommend that you use the CaseInsensitiveHashCodeProvider class for new development. Stattdessen wird empfohlen, dass Sie das-Objekt verwenden, das System.StringComparer von der-,-oder-Eigenschaft zurückgegeben wird StringComparer.CurrentCultureIgnoreCase StringComparer.InvariantCultureIgnoreCase StringComparer.OrdinalIgnoreCase .Instead, we recommend that you use the System.StringComparer object returned by the StringComparer.CurrentCultureIgnoreCase, StringComparer.InvariantCultureIgnoreCase, or StringComparer.OrdinalIgnoreCase property.

Die Objekte, die von einem als Schlüssel verwendet Hashtable werden, müssen die Object.GetHashCode -Methode (oder die IHashCodeProvider -Schnittstelle) und die- Object.Equals Methode (oder die- IComparer Schnittstelle) überschreiben.The objects used as keys by a Hashtable are required to override the Object.GetHashCode method (or the IHashCodeProvider interface) and the Object.Equals method (or the IComparer interface). Bei der Implementierung von Methoden oder Schnittstellen muss die Groß-/Kleinschreibung auf dieselbe Weise behandelt werden. Andernfalls verhält sich das Hashtable möglicherweise falsch.The implementation of both methods or interfaces must handle case sensitivity the same way; otherwise, the Hashtable might behave incorrectly. Wenn Hashtable Sie z. b. erstellen, müssen Sie diese Klasse mit der- CaseInsensitiveComparer Klasse oder einer beliebigen Implementierung ohne Berücksichtigung der Groß-/Kleinschreibung verwenden IComparer .For example, when creating a Hashtable, you must use this class with the CaseInsensitiveComparer class or any case-insensitive IComparer implementation.

Konstruktoren

CaseInsensitiveHashCodeProvider()

Initialisiert eine neue Instanz der CaseInsensitiveHashCodeProvider-Klasse mit der CurrentCulture des aktuellen Threads.Initializes a new instance of the CaseInsensitiveHashCodeProvider class using the CurrentCulture of the current thread.

CaseInsensitiveHashCodeProvider(CultureInfo)

Initialisiert eine neue Instanz der CaseInsensitiveHashCodeProvider-Klasse unter Verwendung des angegebenen CultureInfo.Initializes a new instance of the CaseInsensitiveHashCodeProvider class using the specified CultureInfo.

Eigenschaften

Default

Ruft eine Instanz von CaseInsensitiveHashCodeProvider ab, die der CurrentCulture des aktuellen Threads zugeordnet und jederzeit verfügbar ist.Gets an instance of CaseInsensitiveHashCodeProvider that is associated with the CurrentCulture of the current thread and that is always available.

DefaultInvariant

Ruft eine Instanz von CaseInsensitiveHashCodeProvider ab, die InvariantCulture zugeordnet und jederzeit verfügbar ist.Gets an instance of CaseInsensitiveHashCodeProvider that is associated with InvariantCulture and that is always available.

Methoden

Equals(Object)

Bestimmt, ob das angegebene Objekt gleich dem aktuellen Objekt ist.Determines whether the specified object is equal to the current object.

(Geerbt von Object)
GetHashCode()

Dient als die Standard-HashfunktionServes as the default hash function.

(Geerbt von Object)
GetHashCode(Object)

Gibt einen Hashcode für das angegebene Objekt zurück, wobei im verwendeten Hashalgorithmus die Groß- und Kleinschreibung von Zeichenfolgen ignoriert wird.Returns a hash code for the given object, using a hashing algorithm that ignores the case of strings.

GetType()

Ruft den Type der aktuellen Instanz ab.Gets the Type of the current instance.

(Geerbt von Object)
MemberwiseClone()

Erstellt eine flache Kopie des aktuellen Object.Creates a shallow copy of the current Object.

(Geerbt von Object)
ToString()

Gibt eine Zeichenfolge zurück, die das aktuelle Objekt darstellt.Returns a string that represents the current object.

(Geerbt von Object)

Gilt für:

Weitere Informationen