CaseInsensitiveHashCodeProvider Constructores
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í.
Inicializa una nueva instancia de la clase CaseInsensitiveHashCodeProvider.
Sobrecargas
CaseInsensitiveHashCodeProvider() |
Inicializa una nueva instancia de la clase CaseInsensitiveHashCodeProvider mediante la propiedad CurrentCulture del subproceso actual. |
CaseInsensitiveHashCodeProvider(CultureInfo) |
Inicializa una nueva instancia de la clase CaseInsensitiveHashCodeProvider utilizando la clase CultureInfo especificada. |
CaseInsensitiveHashCodeProvider()
Inicializa una nueva instancia de la clase CaseInsensitiveHashCodeProvider mediante la propiedad CurrentCulture del subproceso actual.
public:
CaseInsensitiveHashCodeProvider();
public CaseInsensitiveHashCodeProvider ();
Public Sub New ()
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
Cuando se crea la CaseInsensitiveHashCodeProvider instancia con este constructor, se guarda el Thread.CurrentCulture del subproceso actual. Los procedimientos de comparación usan la referencia cultural guardada para determinar las reglas de mayúsculas y minúsculas; por lo tanto, las comparaciones de código hash pueden tener resultados diferentes en función de la referencia cultural. Para obtener más información sobre las comparaciones específicas de la referencia cultural, consulte el espacio de nombres y globalización System.Globalizationy la localización.
Consulte también
- CurrentCulture
- CultureInfo
- CompareInfo
- Realizar operaciones de cadenas que no tienen en cuenta las referencias culturales en colecciones
Se aplica a
CaseInsensitiveHashCodeProvider(CultureInfo)
Inicializa una nueva instancia de la clase CaseInsensitiveHashCodeProvider utilizando la clase CultureInfo especificada.
public:
CaseInsensitiveHashCodeProvider(System::Globalization::CultureInfo ^ culture);
public CaseInsensitiveHashCodeProvider (System.Globalization.CultureInfo culture);
new System.Collections.CaseInsensitiveHashCodeProvider : System.Globalization.CultureInfo -> System.Collections.CaseInsensitiveHashCodeProvider
Public Sub New (culture As CultureInfo)
Parámetros
- culture
- CultureInfo
CultureInfo que debe usarse para el nuevo objeto CaseInsensitiveHashCodeProvider.
Excepciones
culture
es null
.
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
Los procedimientos de comparación usan el especificado System.Globalization.CultureInfo para determinar las reglas de mayúsculas y minúsculas. Las comparaciones de código hash pueden tener resultados diferentes en función de la referencia cultural. Para obtener más información sobre las comparaciones específicas de la referencia cultural, consulte el espacio de nombres y globalización System.Globalizationy la localización.
Consulte también
- CultureInfo
- Realizar operaciones de cadenas que no tienen en cuenta las referencias culturales en colecciones