CollectionsUtil 클래스

정의

문자열의 대/소문자를 무시하는 컬렉션을 만듭니다.

public ref class CollectionsUtil
public class CollectionsUtil
type CollectionsUtil = class
Public Class CollectionsUtil
상속
CollectionsUtil

예제

다음 예제에서는 해시 테이블과 정렬된 목록의 두 컬렉션을 사용하여 도시 그룹에 대한 모집단 값을 저장합니다. 값은 도시 이름을 키로 사용하여 컬렉션에서 검색됩니다. 도시 이름은 대/소문자를 구분하지 않는 키로 사용하는 것을 표시하기 위해 혼합된 경우에 있습니다.

#using <System.dll>

using namespace System;
using namespace System::Collections;
using namespace System::Collections::Specialized;

ref class TestCollectionsUtils
{
public:
    static void Main()
    {
        Hashtable^ population1 = CollectionsUtil::CreateCaseInsensitiveHashtable();

        population1["Trapperville"] = 15;
        population1["Doggerton"] = 230;
        population1["New Hollow"] = 1234;
        population1["McHenry"] = 185;

        // Select cities from the table using mixed case.
        Console::WriteLine("Case insensitive hashtable results:\n");
        Console::WriteLine("{0}'s population is: {1}", "Trapperville", population1["trapperville"]);
        Console::WriteLine("{0}'s population is: {1}", "Doggerton", population1["DOGGERTON"]);
        Console::WriteLine("{0}'s population is: {1}", "New Hollow", population1["New hoLLow"]);
        Console::WriteLine("{0}'s population is: {1}", "McHenry", population1["MchenrY"]);

        SortedList^ population2 = CollectionsUtil::CreateCaseInsensitiveSortedList();

        for each (String^ city in population1->Keys)
        {
            population2->Add(city, population1[city]);
        }

        // Select cities from the sorted list using mixed case.
        Console::WriteLine("\nCase insensitive sorted list results:\n");
        Console::WriteLine("{0}'s population is: {1}", "Trapperville", population2["trapPeRVille"]);
        Console::WriteLine("{0}'s population is: {1}", "Doggerton", population2["dOGGeRtON"]);
        Console::WriteLine("{0}'s population is: {1}", "New Hollow", population2["nEW hOLLOW"]);
        Console::WriteLine("{0}'s population is: {1}", "McHenry", population2["MchEnrY"]);
    }
};

int main()
{
    TestCollectionsUtils::Main();
}

// This program displays the following output to the console
//
// Case insensitive hashtable results:
//
// Trapperville's population is: 15
// Doggerton's population is: 230
// New Hollow's population is: 1234
// McHenry's population is: 185
//
// Case insensitive sorted list results:
//
// Trapperville's population is: 15
// Doggerton's population is: 230
// New Hollow's population is: 1234
// McHenry's population is: 185
using System;
using System.Collections;
using System.Collections.Specialized;

class TestCollectionsUtils
{
    public static void Main()
    {
        Hashtable population1 = CollectionsUtil.CreateCaseInsensitiveHashtable();

        population1["Trapperville"] = 15;
        population1["Doggerton"] = 230;
        population1["New Hollow"] = 1234;
        population1["McHenry"] = 185;

        // Select cities from the table using mixed case.
        Console.WriteLine("Case insensitive hashtable results:\n");
        Console.WriteLine("{0}'s population is: {1}", "Trapperville", population1["trapperville"]);
        Console.WriteLine("{0}'s population is: {1}", "Doggerton", population1["DOGGERTON"]);
        Console.WriteLine("{0}'s population is: {1}", "New Hollow", population1["New hoLLow"]);
        Console.WriteLine("{0}'s population is: {1}", "McHenry", population1["MchenrY"]);

        SortedList population2 = CollectionsUtil.CreateCaseInsensitiveSortedList();

        foreach (string city in population1.Keys)
        {
           population2.Add(city, population1[city]);
        }

        // Select cities from the sorted list using mixed case.
        Console.WriteLine("\nCase insensitive sorted list results:\n");
        Console.WriteLine("{0}'s population is: {1}", "Trapperville", population2["trapPeRVille"]);
        Console.WriteLine("{0}'s population is: {1}", "Doggerton", population2["dOGGeRtON"]);
        Console.WriteLine("{0}'s population is: {1}", "New Hollow", population2["nEW hOLLOW"]);
        Console.WriteLine("{0}'s population is: {1}", "McHenry", population2["MchEnrY"]);
    }
}

// This program displays the following output to the console
//
// Case insensitive hashtable results:
//
// Trapperville's population is: 15
// Doggerton's population is: 230
// New Hollow's population is: 1234
// McHenry's population is: 185
//
// Case insensitive sorted list results:
//
// Trapperville's population is: 15
// Doggerton's population is: 230
// New Hollow's population is: 1234
// McHenry's population is: 185
Imports System.Collections
Imports System.Collections.Specialized

Class TestCollectionsUtils
    Public Shared Sub Main()
        Dim population1 As Hashtable = CollectionsUtil.CreateCaseInsensitiveHashtable()

        population1("Trapperville") = 15
        population1("Doggerton") = 230
        population1("New Hollow") = 1234
        population1("McHenry") = 185

        ' Select cities from the table using mixed case.
        Console.WriteLine("Case insensitive hashtable results:" + Environment.NewLine)
        Console.WriteLine("{0}'s population is: {1}", "Trapperville", population1("trapperville"))
        Console.WriteLine("{0}'s population is: {1}", "Doggerton", population1("DOGGERTON"))
        Console.WriteLine("{0}'s population is: {1}", "New Hollow", population1("New hoLLow"))
        Console.WriteLine("{0}'s population is: {1}", "McHenry", population1("MchenrY"))

        Dim population2 As SortedList = CollectionsUtil.CreateCaseInsensitiveSortedList()

        For Each city As String In population1.Keys
            population2.Add(city, population1(city))
        Next city

        ' Select cities from the sorted list using mixed case.
        Console.WriteLine(Environment.NewLine + "Case insensitive sorted list results:" + Environment.NewLine)
        Console.WriteLine("{0}'s population is: {1}", "Trapperville", population2("trapPeRVille"))
        Console.WriteLine("{0}'s population is: {1}", "Doggerton", population2("dOGGeRtON"))
        Console.WriteLine("{0}'s population is: {1}", "New Hollow", population2("nEW hOLLOW"))
        Console.WriteLine("{0}'s population is: {1}", "McHenry", population2("MchEnrY"))
    End Sub
End Class

' This program displays the following output to the console
'
' Case insensitive hashtable results:
'
' Trapperville's population is: 15
' Doggerton's population is: 230
' New Hollow's population is: 1234
' McHenry's population is: 185
'
' Case insensitive sorted list results:
'
' Trapperville's population is: 15
' Doggerton's population is: 230
' New Hollow's population is: 1234
' McHenry's population is: 185

설명

이러한 메서드는 해시 코드 공급자 및 비교자의 대/소문자를 구분하지 않는 구현을 사용하여 컬렉션의 대/소문자를 구분하지 않는 instance 생성합니다. 결과 instance 다르게 동작할 수 있지만 해당 클래스의 다른 인스턴스처럼 사용할 수 있습니다.

예를 들어 "hello" 및 "HELLO" 키가 있는 두 개체를 해시 테이블에 추가해야 한다고 가정해 보겠습니다. 대/소문자를 구분하는 해시 테이블은 두 개의 다른 항목을 만듭니다. 반면 대/소문자를 구분하지 않는 해시 테이블은 두 번째 개체를 추가할 때 예외를 throw합니다.

생성자

CollectionsUtil()

CollectionsUtil 클래스의 새 인스턴스를 초기화합니다.

메서드

CreateCaseInsensitiveHashtable()

기본 초기 용량을 갖는 Hashtable 클래스의 대/소문자를 구분하지 않는 새 인스턴스를 만듭니다.

CreateCaseInsensitiveHashtable(IDictionary)

지정된 사전의 항목을 복사된 항목의 수와 초기 용량이 같은 Hashtable 클래스의 대/소문자를 구분하지 않는 새 인스턴스로 복사합니다.

CreateCaseInsensitiveHashtable(Int32)

초기 용량이 지정된 Hashtable 클래스의 대/소문자를 구분하지 않는 새 인스턴스를 만듭니다.

CreateCaseInsensitiveSortedList()

문자열의 대/소문자를 구분하지 않는 SortedList 클래스의 새 인스턴스를 만듭니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

스레드 보안

Hashtable 하나의 작성기와 여러 판독기를 동시에 지원할 수 있습니다. 여러 기록기를 지원하려면 메서드에서 반환 Synchronized(Hashtable) 된 래퍼를 통해 모든 작업을 수행해야 합니다.

SortedList 지원할 수 있습니다 여러 판독기 동시에 따라 컬렉션을 수정 되지 않습니다. 의 SortedList스레드 안전을 보장하려면 메서드에서 반환 Synchronized(SortedList) 된 래퍼를 통해 모든 작업을 수행해야 합니다.

컬렉션을 열거 되지 본질적으로 스레드로부터 안전한 프로시저가 있습니다. 컬렉션이 동기화되어 있을 때 다른 스레드에서 해당 컬렉션을 수정할 수 있으므로 이렇게 되면 열거자에서 예외가 throw됩니다. 열거하는 동안 스레드로부터 안전을 보장하려면 전체 열거를 수행하는 동안 컬렉션을 잠그거나 다른 스레드에서 변경된 내용으로 인해 발생한 예외를 catch하면 됩니다.

추가 정보