CaseInsensitiveHashCodeProvider Clase
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Precaución
Please use StringComparer instead.
Precaución
CaseInsensitiveHashCodeProvider has been deprecated. Use StringComparer instead.
Proporciona un código hash para un objeto y utiliza un algoritmo hash que no distingue entre mayúsculas y minúsculas en las cadenas.
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
- Herencia
-
CaseInsensitiveHashCodeProvider
- Atributos
- Implementaciones
Ejemplos
En el ejemplo de código siguiente se crea una tabla hash que distingue mayúsculas de minúsculas y una tabla hash que no distingue mayúsculas de minúsculas y se muestra la diferencia en su comportamiento, incluso si ambos contienen los mismos elementos.
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
Comentarios
CaseInsensitiveHashCodeProvider implementa la IHashCodeProvider interfaz que admite comparaciones que no distinguen mayúsculas de minúsculas en cadenas, igual que CaseInsensitiveComparer implementa la IComparer interfaz que admite comparaciones que no distinguen mayúsculas de minúsculas en cadenas.
Importante
No se recomienda usar la CaseInsensitiveHashCodeProvider
clase para el nuevo desarrollo. En su lugar, se recomienda usar el System.StringComparer objeto devuelto por la StringComparer.CurrentCultureIgnoreCasepropiedad , StringComparer.InvariantCultureIgnoreCaseo StringComparer.OrdinalIgnoreCase .
Los objetos usados como claves por un Hashtable elemento son necesarios para invalidar el Object.GetHashCode método (o la IHashCodeProvider interfaz) y el Object.Equals método (o la IComparer interfaz). La implementación de ambos métodos o interfaces debe controlar la distinción entre mayúsculas y minúsculas de la misma manera; de lo contrario, Hashtable podría comportarse incorrectamente. Por ejemplo, al crear un Hashtable, debe usar esta clase con la CaseInsensitiveComparer clase o cualquier implementación que no distingue mayúsculas de minúsculas IComparer .
Constructores
CaseInsensitiveHashCodeProvider() |
Obsoletos.
Obsoletos.
Inicializa una nueva instancia de la clase CaseInsensitiveHashCodeProvider mediante la propiedad CurrentCulture del subproceso actual. |
CaseInsensitiveHashCodeProvider(CultureInfo) |
Obsoletos.
Obsoletos.
Inicializa una nueva instancia de la clase CaseInsensitiveHashCodeProvider utilizando la clase CultureInfo especificada. |
Propiedades
Default |
Obsoletos.
Obsoletos.
Obtiene una instancia de CaseInsensitiveHashCodeProvider que está asociada a la propiedad CurrentCulture del subproceso actual y que siempre está disponible. |
DefaultInvariant |
Obsoletos.
Obsoletos.
Obtiene una instancia de CaseInsensitiveHashCodeProvider que está asociada a la propiedad InvariantCulture y que siempre está disponible. |
Métodos
Equals(Object) |
Obsoletos.
Obsoletos.
Determina si el objeto especificado es igual que el objeto actual. (Heredado de Object) |
GetHashCode() |
Obsoletos.
Obsoletos.
Sirve como la función hash predeterminada. (Heredado de Object) |
GetHashCode(Object) |
Obsoletos.
Obsoletos.
Devuelve un código hash para el objeto dado y utiliza un algoritmo hash que no distingue entre mayúsculas y minúsculas en las cadenas. |
GetType() |
Obsoletos.
Obsoletos.
Obtiene el Type de la instancia actual. (Heredado de Object) |
MemberwiseClone() |
Obsoletos.
Obsoletos.
Crea una copia superficial del Object actual. (Heredado de Object) |
ToString() |
Obsoletos.
Obsoletos.
Devuelve una cadena que representa el objeto actual. (Heredado de Object) |