SortedList 클래스

정의

키를 기준으로 정렬되고 키와 인덱스로 액세스할 수 있는 키/값 쌍의 컬렉션을 나타냅니다.

public ref class SortedList : System::Collections::IDictionary
public ref class SortedList : ICloneable, System::Collections::IDictionary
public class SortedList : System.Collections.IDictionary
public class SortedList : ICloneable, System.Collections.IDictionary
[System.Serializable]
public class SortedList : ICloneable, System.Collections.IDictionary
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class SortedList : ICloneable, System.Collections.IDictionary
type SortedList = class
    interface ICollection
    interface IEnumerable
    interface IDictionary
type SortedList = class
    interface ICollection
    interface IEnumerable
    interface IDictionary
    interface ICloneable
[<System.Serializable>]
type SortedList = class
    interface IDictionary
    interface ICollection
    interface IEnumerable
    interface ICloneable
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type SortedList = class
    interface IDictionary
    interface ICollection
    interface IEnumerable
    interface ICloneable
Public Class SortedList
Implements IDictionary
Public Class SortedList
Implements ICloneable, IDictionary
상속
SortedList
특성
구현

예제

다음 코드 예제에서는 개체를 만들고 초기화하는 SortedList 방법과 해당 키와 값을 출력하는 방법을 보여 있습니다.

#using <system.dll>

using namespace System;
using namespace System::Collections;
public ref class SamplesSortedList
{
public:
   static void PrintKeysAndValues( SortedList^ myList )
   {
      Console::WriteLine( "\t-KEY-\t-VALUE-" );
      for ( int i = 0; i < myList->Count; i++ )
      {
         Console::WriteLine( "\t{0}:\t{1}", myList->GetKey( i ), myList->GetByIndex( i ) );

      }
      Console::WriteLine();
   }

};

int main()
{

   // Creates and initializes a new SortedList.
   SortedList^ mySL = gcnew SortedList;
   mySL->Add( "Third", "!" );
   mySL->Add( "Second", "World" );
   mySL->Add( "First", "Hello" );

   // Displays the properties and values of the SortedList.
   Console::WriteLine( "mySL" );
   Console::WriteLine( "  Count:    {0}", mySL->Count );
   Console::WriteLine( "  Capacity: {0}", mySL->Capacity );
   Console::WriteLine( "  Keys and Values:" );
   SamplesSortedList::PrintKeysAndValues( mySL );
}

/*
This code produces the following output.

mySL
Count:    3
Capacity: 16
Keys and Values:
-KEY-    -VALUE-
First:    Hello
Second:    World
Third:    !
*/
using System;
using System.Collections;

public class SamplesSortedList2
{
    public static void Main()
    {
        // Creates and initializes a new SortedList.
        SortedList mySL = new SortedList();
        mySL.Add("Third", "!");
        mySL.Add("Second", "World");
        mySL.Add("First", "Hello");

        // Displays the properties and values of the SortedList.
        Console.WriteLine("mySL");
        Console.WriteLine("  Count:    {0}", mySL.Count);
        Console.WriteLine("  Capacity: {0}", mySL.Capacity);
        Console.WriteLine("  Keys and Values:");
        PrintKeysAndValues(mySL);
    }

    public static void PrintKeysAndValues(SortedList myList)
    {
        Console.WriteLine("\t-KEY-\t-VALUE-");
        for (int i = 0; i < myList.Count; i++)
        {
            Console.WriteLine("\t{0}:\t{1}", myList.GetKey(i), myList.GetByIndex(i));
        }
        Console.WriteLine();
    }
}
/*
This code produces the following output.

mySL
  Count:    3
  Capacity: 16
  Keys and Values:
    -KEY-    -VALUE-
    First:    Hello
    Second:    World
    Third:    !
*/
Imports System.Collections

Public Class SamplesSortedList    
    
    Public Shared Sub Main()
        
        ' Creates and initializes a new SortedList.
        Dim mySL As New SortedList()
        mySL.Add("Third", "!")
        mySL.Add("Second", "World")
        mySL.Add("First", "Hello")
        
        ' Displays the properties and values of the SortedList.
        Console.WriteLine("mySL")
        Console.WriteLine("  Count:    {0}", mySL.Count)
        Console.WriteLine("  Capacity: {0}", mySL.Capacity)
        Console.WriteLine("  Keys and Values:")
        PrintKeysAndValues(mySL)
    End Sub
    
    Public Shared Sub PrintKeysAndValues(myList As SortedList)
        Console.WriteLine(ControlChars.Tab & "-KEY-" & ControlChars.Tab & _
           "-VALUE-")
        Dim i As Integer
        For i = 0 To myList.Count - 1
            Console.WriteLine(ControlChars.Tab & "{0}:" & ControlChars.Tab & _
               "{1}", myList.GetKey(i), myList.GetByIndex(i))
        Next i
        Console.WriteLine()
    End Sub
End Class

' This code produces the following output.
' 
' mySL
'   Count:    3
'   Capacity: 16
'   Keys and Values:
'     -KEY-     -VALUE-
'     First:    Hello
'     Second:   World
'     Third:    !

설명

요소는 SortedList 모든 구현의 요소와 같은 키 또는 구현의 IDictionary 요소와 같은 인덱스로 액세스할 수 있습니다 IList .

중요

새 개발에 클래스를 SortedList 사용하지 않는 것이 좋습니다. 대신 제네릭 System.Collections.Generic.SortedList<TKey,TValue> 클래스를 사용하는 것이 좋습니다. 자세한 내용은 GitHub에서 제네릭이 아닌 컬렉션을 사용하면 안 됨 을 참조하세요.

개체는 SortedList 내부적으로 목록의 요소를 저장하기 위해 두 개의 배열을 유지 관리합니다. 즉, 키에 대한 배열 하나와 연결된 값에 대한 다른 배열입니다. 각 요소는 개체로 액세스할 수 있는 키/값 쌍입니다 DictionaryEntry . 키는 일 수 없지만 null값은 일 수 있습니다.

개체의 SortedList 용량은 가 보유할 수 있는 SortedList 요소의 수입니다. 요소가 에 SortedList추가되면 재할당을 통해 필요에 따라 용량이 자동으로 증가합니다. 를 호출 TrimToSize 하거나 속성을 명시적으로 설정하여 용량을 Capacity 줄일 수 있습니다.

.NET Framework 전용: 매우 큰 SortedList 개체의 경우 런타임 환경에서 구성 요소의 <gcAllowVeryLargeObjects> 특성을 로 설정 enabled 하여 64비트 시스템에서 최대 용량을 20억 요소로 true 늘릴 수 있습니다.

개체의 SortedList 요소는 가 생성될 때 SortedList 지정된 특정 IComparer 구현에 따라 또는 키 자체에서 제공하는 구현에 IComparable 따라 키별로 정렬됩니다. 두 경우 모두 에서 SortedList 중복 키를 허용하지 않습니다.

인덱스 시퀀스는 정렬 시퀀스를 기반으로합니다. 요소가 추가되면 올바른 정렬 순서로 에 SortedList 삽입되고 인덱싱이 적절하게 조정됩니다. 요소가 제거되면 인덱싱도 그에 따라 조정됩니다. 따라서 요소가 개체에서 추가되거나 제거되면 특정 키/값 쌍의 인덱스가 SortedList 변경될 수 있습니다.

개체에 대한 SortedList 작업은 정렬로 인해 개체의 Hashtable 작업보다 느린 경향이 있습니다. 그러나 는 SortedList 연결된 키 또는 인덱스를 통해 값에 대한 액세스를 허용하여 더 많은 유연성을 제공합니다.

이 컬렉션의 요소는 정수 인덱스로 액세스할 수 있습니다. 이 컬렉션의 인덱스는 0부터 시작 합니다.

C# 언어(for eachVisual Basic의 경우)의 문은 foreach 컬렉션에 있는 요소 형식의 개체를 반환합니다. 개체의 SortedList 각 요소는 키/값 쌍이므로 요소 형식은 키의 형식이나 값 형식이 아닙니다. 대신 요소 형식은 입니다 DictionaryEntry. 예를 들면 다음과 같습니다.

for each (DictionaryEntry de in mySortedList)
{
    //...
}
foreach (DictionaryEntry de in mySortedList)
{
    //...
}
For Each de As DictionaryEntry In mySortedList
    '...
Next de

문은 foreach 열거자를 둘러싼 래퍼로, 컬렉션에 쓰는 것이 아니라 읽는 것만 허용합니다.

생성자

SortedList()

비어 있는 상태이고 기본 초기 용량을 가지며 SortedList 개체에 추가된 각 키에서 구현하는 IComparable 인터페이스에 따라 정렬되는 SortedList 클래스의 새 인스턴스를 초기화합니다.

SortedList(IComparer)

비어 있고 기본 초기 용량을 갖고 있으며 지정된 SortedList 인터페이스에 따라 정렬되는 IComparer 클래스의 새 인스턴스를 초기화합니다.

SortedList(IComparer, Int32)

비어 있고 지정된 초기 용량을 갖고 있으며 지정된 SortedList 인터페이스에 따라 정렬되는 IComparer 클래스의 새 인스턴스를 초기화합니다.

SortedList(IDictionary)

지정된 사전에서 복사된 요소가 포함되어 있고 복사된 요소의 수와 같은 초기 용량을 갖고 있으며 각 키에서 구현된 SortedList 인터페이스에 따라 정렬되는 IComparable 클래스의 새 인스턴스를 초기화합니다.

SortedList(IDictionary, IComparer)

지정된 사전에서 복사된 요소가 포함되어 있고 복사된 요소의 수와 같은 초기 용량을 갖고 있으며 지정된 SortedList 인터페이스에 따라 정렬되는 IComparer 클래스의 새 인스턴스를 초기화합니다.

SortedList(Int32)

비어 있는 상태이고 지정된 초기 용량을 가지며 SortedList 개체에 추가된 각 키에서 구현된 IComparable 인터페이스에 따라 정렬되는 SortedList 클래스의 새 인스턴스를 초기화합니다.

속성

Capacity

SortedList 개체의 용량을 가져오거나 설정합니다.

Count

SortedList 개체에 포함된 요소 수를 가져옵니다.

IsFixedSize

SortedList 개체의 크기가 고정되어 있는지 여부를 나타내는 값을 가져옵니다.

IsReadOnly

SortedList 개체가 읽기 전용인지 여부를 나타내는 값을 가져옵니다.

IsSynchronized

SortedList 개체에 대한 액세스가 동기화되어 스레드로부터 안전하게 보호되는지 여부를 나타내는 값을 가져옵니다.

Item[Object]

SortedList 개체의 특정 키와 연관된 값을 가져오거나 설정합니다.

Keys

SortedList 개체의 키를 가져옵니다.

SyncRoot

SortedList 개체에 대한 액세스를 동기화하는 데 사용할 수 있는 개체를 가져옵니다.

Values

SortedList 개체의 값을 가져옵니다.

메서드

Add(Object, Object)

지정한 키와 값을 가진 요소를 SortedList 개체에 추가합니다.

Clear()

SortedList 개체에서 요소를 모두 제거합니다.

Clone()

SortedList 개체의 단순 복사본을 만듭니다.

Contains(Object)

SortedList 개체에 특정 키가 포함되어 있는지 여부를 확인합니다.

ContainsKey(Object)

SortedList 개체에 특정 키가 포함되어 있는지 여부를 확인합니다.

ContainsValue(Object)

SortedList 개체에 특정 값이 포함되어 있는지 여부를 확인합니다.

CopyTo(Array, Int32)

SortedList 요소를 지정한 배열 인덱스에서 시작하여 1차원 Array 개체에 복사합니다.

Equals(Object)

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

(다음에서 상속됨 Object)
GetByIndex(Int32)

SortedList 개체의 지정한 인덱스에서 값을 가져옵니다.

GetEnumerator()

IDictionaryEnumerator 개체를 반복하는 SortedList 개체를 반환합니다.

GetHashCode()

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

(다음에서 상속됨 Object)
GetKey(Int32)

SortedList 개체의 지정한 인덱스에서 키를 가져옵니다.

GetKeyList()

SortedList 개체의 키를 가져옵니다.

GetType()

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

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

SortedList 개체의 값을 가져옵니다.

IndexOfKey(Object)

SortedList 개체의 지정된 키 인덱스(0부터 시작)를 반환합니다.

IndexOfValue(Object)

지정한 값이 SortedList 개체에서 맨 처음 발견되는 인덱스(0부터 시작)를 반환합니다.

MemberwiseClone()

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

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

SortedList 개체에서 지정된 키를 가진 요소를 제거합니다.

RemoveAt(Int32)

SortedList 개체의 지정한 인덱스에서 요소를 제거합니다.

SetByIndex(Int32, Object)

SortedList 개체의 지정한 인덱스에서 값을 바꿉니다.

Synchronized(SortedList)

SortedList 개체에 대해 동기화되어 스레드로부터 안전하게 보호되는 래퍼를 반환합니다.

ToString()

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

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

용량을 SortedList 개체의 실제 요소 수로 설정합니다.

명시적 인터페이스 구현

IEnumerable.GetEnumerator()

IEnumerator를 반복하는 SortedList를 반환합니다.

확장 메서드

Cast<TResult>(IEnumerable)

IEnumerable의 요소를 지정된 형식으로 캐스팅합니다.

OfType<TResult>(IEnumerable)

지정된 형식에 따라 IEnumerable의 요소를 필터링합니다.

AsParallel(IEnumerable)

쿼리를 병렬화할 수 있도록 합니다.

AsQueryable(IEnumerable)

IEnumerableIQueryable로 변환합니다.

적용 대상

스레드 보안

공용 정적 (Shared Visual Basic의)이 형식의 멤버는 스레드로부터 안전 합니다. 인스턴스 구성원은 스레드로부터의 안전성이 보장되지 않습니다.

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

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

추가 정보