CaseInsensitiveComparer CaseInsensitiveComparer CaseInsensitiveComparer CaseInsensitiveComparer Class

정의

문자열의 대/소문자를 무시하고 두 개체를 비교합니다.Compares two objects for equivalence, ignoring the case of strings.

public ref class CaseInsensitiveComparer : System::Collections::IComparer
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CaseInsensitiveComparer : System.Collections.IComparer
type CaseInsensitiveComparer = class
    interface IComparer
Public Class CaseInsensitiveComparer
Implements IComparer
상속
CaseInsensitiveComparerCaseInsensitiveComparerCaseInsensitiveComparerCaseInsensitiveComparer
특성
구현

예제

다음 코드 예제에서는 대/소문자 구분 해시 테이블 및 대/소문자 해시 테이블을 만들고 모두 동일한 요소를 포함 하는 경우에 해당 동작의 차이점을 설명 합니다.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 '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

설명

CaseInsensitiveComparer 구현 된 IComparer 처럼 문자열 대/소문자 구분 비교를 지 원하는 인터페이스 CaseInsensitiveHashCodeProvider 구현를 IHashCodeProvider 문자열에 대/소문자 구분 비교를 지 원하는 인터페이스.CaseInsensitiveComparer implements the IComparer interface supporting case-insensitive comparisons on strings, just as CaseInsensitiveHashCodeProvider implements the IHashCodeProvider interface supporting case-insensitive comparisons on strings.

중요

사용 하는 권장 하지 않습니다는 CaseInsensitiveComparer 새로운 개발에 대 한 클래스입니다.We don't recommend that you use the CaseInsensitiveComparer class for new development. 사용 하는 권장 대신 합니다 System.StringComparer 에서 반환 된 개체를 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.

합니다 Comparer 클래스의 기본 구현은 IComparer 인터페이스 및 대/소문자 구분 문자열 비교를 수행 합니다.The Comparer class is the default implementation of the IComparer interface and performs case-sensitive string comparisons.

키로 사용 하는 개체를 Hashtable 재정의 하는 데 필요한 합니다 Object.GetHashCode 메서드 (또는 IHashCodeProvider 인터페이스) 및 Object.Equals 메서드 (또는 IComparer 인터페이스).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). 메서드나 인터페이스 구현의 대/소문자 구분; 동일한 방식으로 처리 해야 합니다. 그렇지 않은 경우는 Hashtable 올바르게 작동할 수 있습니다.The implementation of both methods or interfaces must handle case sensitivity the same way; otherwise, the Hashtable might behave incorrectly. 예를 들어, 만들 때를 Hashtable를 사용 하 여이 클래스를 사용 해야 합니다 CaseInsensitiveHashCodeProvider 클래스 또는 대/소문자 IHashCodeProvider 구현.For example, when creating a Hashtable, you must use this class with the CaseInsensitiveHashCodeProvider class or any case-insensitive IHashCodeProvider implementation.

문자열 비교는 문화권에 따라 다른 결과가 있을 수 있습니다.String comparisons might have different results depending on the culture. 문화권별 비교에 대 한 자세한 내용은 참조는 System.Globalization 네임 스페이스 및 전역화 및 지역화합니다.For more information on culture-specific comparisons, see the System.Globalization namespace and Globalization and Localization.

생성자

CaseInsensitiveComparer() CaseInsensitiveComparer() CaseInsensitiveComparer() CaseInsensitiveComparer()

현재 스레드의 CaseInsensitiveComparer를 사용하여 CurrentCulture 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the CaseInsensitiveComparer class using the CurrentCulture of the current thread.

CaseInsensitiveComparer(CultureInfo) CaseInsensitiveComparer(CultureInfo) CaseInsensitiveComparer(CultureInfo) CaseInsensitiveComparer(CultureInfo)

지정된 CaseInsensitiveComparer를 사용하여 CultureInfo 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the CaseInsensitiveComparer class using the specified CultureInfo.

속성

Default Default Default Default

현재 스레드의 CaseInsensitiveComparer와 관련되어 있고 항상 사용 가능한 CurrentCulture의 인스턴스를 가져옵니다.Gets an instance of CaseInsensitiveComparer that is associated with the CurrentCulture of the current thread and that is always available.

DefaultInvariant DefaultInvariant DefaultInvariant DefaultInvariant

CaseInsensitiveComparer와 관련되어 있고 항상 사용 가능한 InvariantCulture의 인스턴스를 가져옵니다.Gets an instance of CaseInsensitiveComparer that is associated with InvariantCulture and that is always available.

메서드

Compare(Object, Object) Compare(Object, Object) Compare(Object, Object) Compare(Object, Object)

대/소문자를 구분하지 않고 같은 형식의 두 개체를 비교한 다음 한 개체가 다른 개체보다 작은지, 큰지 또는 두 개체가 같은지 여부를 나타내는 값을 반환합니다.Performs a case-insensitive comparison of two objects of the same type and returns a value indicating whether one is less than, equal to, or greater than the other.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

지정한 개체와 현재 개체가 같은지 여부를 확인합니다.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

기본 해시 함수로 작동합니다.Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

현재 인스턴스의 Type을 가져옵니다.Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

현재 개체를 나타내는 문자열을 반환합니다.Returns a string that represents the current object.

(Inherited from Object)

적용 대상

추가 정보