CaseInsensitiveComparer クラス
アセンブリ: mscorlib (mscorlib.dll 内)

<SerializableAttribute> _ <ComVisibleAttribute(True)> _ Public Class CaseInsensitiveComparer Implements IComparer
[SerializableAttribute] [ComVisibleAttribute(true)] public class CaseInsensitiveComparer : IComparer
[SerializableAttribute] [ComVisibleAttribute(true)] public ref class CaseInsensitiveComparer : IComparer

CaseInsensitiveComparer は、文字列の大文字と小文字を区別しない比較をサポートする IComparer インターフェイスを実装しています。同様に、CaseInsensitiveHashCodeProvider は、文字列の大文字と小文字を区別しない比較をサポートする IHashCodeProvider インターフェイスを実装しています。
Comparer クラスは IComparer インターフェイスの既定の実装で、大文字と小文字を区別する文字列比較を実行します。
Hashtable でキーとして使用されるオブジェクトは、Object.GetHashCode メソッド (または IHashCodeProvider インターフェイス) およびObject.Equals メソッド (または IComparer インターフェイス) を実装または継承している必要があります。メソッドまたはインターフェイスのどちらの実装でも、大文字と小文字の区別を同じ方法で処理する必要があります。そのように実装されていないと、Hashtable が正しく動作しない場合があります。たとえば、Hashtable を作成するとき、このクラスは、CaseInsensitiveHashCodeProvider クラスか大文字と小文字を区別しない IHashCodeProvider 実装と共に使用する必要があります。
文字列比較の結果は、カルチャに応じて異なる場合があります。カルチャ固有の比較の詳細については、System.Globalization 名前空間のトピックおよび「エンコーディングとローカリゼーション」を参照してください。

次に示すのは、大文字と小文字を区別するハッシュ テーブルと、大文字と小文字を区別しないハッシュ テーブルを作成するコード例です。それぞれのハッシュ テーブルに含まれている要素が同じでも、両者の動作は異なることがわかります。
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 */
import System.*; import System.Collections.*; import System.Globalization.*; public class SamplesHashtable { public static void main(String[] args) { // 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.get_DefaultInvariant() , CaseInsensitiveComparer.get_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}", (System.Boolean)myHT1.ContainsKey("first")); Console.WriteLine("first is in myHT2: {0}", (System.Boolean)myHT2.ContainsKey("first")); Console.WriteLine("first is in myHT3: {0}", (System.Boolean)myHT3.ContainsKey("first")); Console.WriteLine("first is in myHT4: {0}", (System.Boolean)myHT4.ContainsKey("first")); } //main } //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 */

System.Collections.CaseInsensitiveComparer


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


CaseInsensitiveComparer コンストラクタ ()
アセンブリ: mscorlib (mscorlib.dll 内)


CaseInsensitiveComparer インスタンスがこのコンストラクタを使用して作成される場合、現在のスレッドの Thread.CurrentCulture は保存されます。比較プロシージャは保存されたカルチャを使用して並べ替え順序と大文字と小文字の規則を判断するので、文字列比較の結果はカルチャによって異なる場合があります。カルチャ固有の比較の詳細については、System.Globalization 名前空間のトピックおよび「エンコーディングとローカリゼーション」を参照してください。

次に示すのは、大文字と小文字を区別するハッシュ テーブルと、大文字と小文字を区別しないハッシュ テーブルを作成するコード例です。それぞれのハッシュ テーブルに含まれている要素が同じでも、両者の動作は異なることがわかります。
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 */
import System.*; import System.Collections.*; import System.Globalization.*; public class SamplesHashtable { public static void main(String[] args) { // 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.get_DefaultInvariant() , CaseInsensitiveComparer.get_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}", (System.Boolean)myHT1.ContainsKey("first")); Console.WriteLine("first is in myHT2: {0}", (System.Boolean)myHT2.ContainsKey("first")); Console.WriteLine("first is in myHT3: {0}", (System.Boolean)myHT3.ContainsKey("first")); Console.WriteLine("first is in myHT4: {0}", (System.Boolean)myHT4.ContainsKey("first")); } //main } //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 */

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


CaseInsensitiveComparer コンストラクタ (CultureInfo)
アセンブリ: mscorlib (mscorlib.dll 内)



比較プロシージャは、並べ替え順序と大文字と小文字の規則を決定するために、指定した System.Globalization.CultureInfo を使用します。文字列比較の結果は、カルチャに応じて異なる場合があります。カルチャ固有の比較の詳細については、System.Globalization 名前空間のトピックおよび「エンコーディングとローカリゼーション」を参照してください。

次に示すのは、大文字と小文字を区別するハッシュ テーブルと、大文字と小文字を区別しないハッシュ テーブルを作成するコード例です。それぞれのハッシュ テーブルに含まれている要素が同じでも、両者の動作は異なることがわかります。
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 */
import System.*; import System.Collections.*; import System.Globalization.*; public class SamplesHashtable { public static void main(String[] args) { // 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.get_DefaultInvariant() , CaseInsensitiveComparer.get_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}", (System.Boolean)myHT1.ContainsKey("first")); Console.WriteLine("first is in myHT2: {0}", (System.Boolean)myHT2.ContainsKey("first")); Console.WriteLine("first is in myHT3: {0}", (System.Boolean)myHT3.ContainsKey("first")); Console.WriteLine("first is in myHT4: {0}", (System.Boolean)myHT4.ContainsKey("first")); } //main } //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 */

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


CaseInsensitiveComparer コンストラクタ

名前 | 説明 |
---|---|
CaseInsensitiveComparer () | 現在のスレッドの Thread.CurrentCulture を使用して、CaseInsensitiveComparer クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |
CaseInsensitiveComparer (CultureInfo) | System.Globalization.CultureInfo を指定して、CaseInsensitiveComparer クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |

CaseInsensitiveComparer プロパティ

名前 | 説明 | |
---|---|---|
![]() | DefaultInvariant | CultureInfo.InvariantCulture に関連付けられた、常に使用できる CaseInsensitiveComparer のインスタンスを取得します。 |

CaseInsensitiveComparer メソッド

名前 | 説明 | |
---|---|---|
![]() | Compare | 同じ型の 2 つのオブジェクトに対して大文字小文字を区別しない比較を実行し、一方が他方よりも小さいか、等しいか、大きいかを示す値を返します。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

CaseInsensitiveComparer メンバ
2 つのオブジェクトが等しいかどうかを比較します。比較時には文字列の大文字と小文字は区別されません。
CaseInsensitiveComparer データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() | DefaultInvariant | CultureInfo.InvariantCulture に関連付けられた、常に使用できる CaseInsensitiveComparer のインスタンスを取得します。 |

名前 | 説明 | |
---|---|---|
![]() | Compare | 同じ型の 2 つのオブジェクトに対して大文字小文字を区別しない比較を実行し、一方が他方よりも小さいか、等しいか、大きいかを示す値を返します。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

- CaseInsensitiveComparerのページへのリンク