OrderedDictionary 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
키 또는 인덱스로 액세스할 수 있는 키/값 쌍의 컬렉션을 나타냅니다.
public ref class OrderedDictionary : System::Collections::IDictionary, System::Collections::Specialized::IOrderedDictionary
public ref class OrderedDictionary : System::Collections::IDictionary, System::Collections::Specialized::IOrderedDictionary, System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable
public ref class OrderedDictionary : System::Collections::Specialized::IOrderedDictionary, System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable
public class OrderedDictionary : System.Collections.IDictionary, System.Collections.Specialized.IOrderedDictionary
[System.Serializable]
public class OrderedDictionary : System.Collections.IDictionary, System.Collections.Specialized.IOrderedDictionary, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
public class OrderedDictionary : System.Collections.Specialized.IOrderedDictionary, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
type OrderedDictionary = class
interface ICollection
interface IEnumerable
interface IDictionary
interface IOrderedDictionary
[<System.Serializable>]
type OrderedDictionary = class
interface IOrderedDictionary
interface IDictionary
interface ICollection
interface IEnumerable
interface ISerializable
interface IDeserializationCallback
type OrderedDictionary = class
interface ICollection
interface IEnumerable
interface IDictionary
interface IOrderedDictionary
interface IDeserializationCallback
interface ISerializable
Public Class OrderedDictionary
Implements IDictionary, IOrderedDictionary
Public Class OrderedDictionary
Implements IDeserializationCallback, IDictionary, IOrderedDictionary, ISerializable
Public Class OrderedDictionary
Implements IDeserializationCallback, IOrderedDictionary, ISerializable
- 상속
-
OrderedDictionary
- 파생
- 특성
- 구현
예제
다음 코드 예제에서는 컬렉션의 OrderedDictionary 생성, 채우기 및 수정뿐만 아니라 두 가지 기법OrderedDictionary을 보여 줍니다. 하나는 속성 및 Values 속성을 사용하고 Keys 다른 하나는 메서드를 통해 GetEnumerator 열거자를 만드는 것입니다.
// The following code example enumerates the elements of a OrderedDictionary.
using System;
using System.Collections;
using System.Collections.Specialized;
public class OrderedDictionarySample
{
public static void Main()
{
// Creates and initializes a OrderedDictionary.
OrderedDictionary myOrderedDictionary = new OrderedDictionary();
myOrderedDictionary.Add("testKey1", "testValue1");
myOrderedDictionary.Add("testKey2", "testValue2");
myOrderedDictionary.Add("keyToDelete", "valueToDelete");
myOrderedDictionary.Add("testKey3", "testValue3");
ICollection keyCollection = myOrderedDictionary.Keys;
ICollection valueCollection = myOrderedDictionary.Values;
// Display the contents using the key and value collections
DisplayContents(keyCollection, valueCollection, myOrderedDictionary.Count);
// Modifying the OrderedDictionary
if (!myOrderedDictionary.IsReadOnly)
{
// Insert a new key to the beginning of the OrderedDictionary
myOrderedDictionary.Insert(0, "insertedKey1", "insertedValue1");
// Modify the value of the entry with the key "testKey2"
myOrderedDictionary["testKey2"] = "modifiedValue";
// Remove the last entry from the OrderedDictionary: "testKey3"
myOrderedDictionary.RemoveAt(myOrderedDictionary.Count - 1);
// Remove the "keyToDelete" entry, if it exists
if (myOrderedDictionary.Contains("keyToDelete"))
{
myOrderedDictionary.Remove("keyToDelete");
}
}
Console.WriteLine(
"{0}Displaying the entries of a modified OrderedDictionary.",
Environment.NewLine);
DisplayContents(keyCollection, valueCollection, myOrderedDictionary.Count);
// Clear the OrderedDictionary and add new values
myOrderedDictionary.Clear();
myOrderedDictionary.Add("newKey1", "newValue1");
myOrderedDictionary.Add("newKey2", "newValue2");
myOrderedDictionary.Add("newKey3", "newValue3");
// Display the contents of the "new" Dictionary using an enumerator
IDictionaryEnumerator myEnumerator =
myOrderedDictionary.GetEnumerator();
Console.WriteLine(
"{0}Displaying the entries of a \"new\" OrderedDictionary.",
Environment.NewLine);
DisplayEnumerator(myEnumerator);
}
// Displays the contents of the OrderedDictionary from its keys and values
public static void DisplayContents(
ICollection keyCollection, ICollection valueCollection, int dictionarySize)
{
String[] myKeys = new String[dictionarySize];
String[] myValues = new String[dictionarySize];
keyCollection.CopyTo(myKeys, 0);
valueCollection.CopyTo(myValues, 0);
// Displays the contents of the OrderedDictionary
Console.WriteLine(" INDEX KEY VALUE");
for (int i = 0; i < dictionarySize; i++)
{
Console.WriteLine(" {0,-5} {1,-25} {2}",
i, myKeys[i], myValues[i]);
}
Console.WriteLine();
}
// Displays the contents of the OrderedDictionary using its enumerator
public static void DisplayEnumerator(IDictionaryEnumerator myEnumerator)
{
Console.WriteLine(" KEY VALUE");
while (myEnumerator.MoveNext())
{
Console.WriteLine(" {0,-25} {1}",
myEnumerator.Key, myEnumerator.Value);
}
}
}
/*
This code produces the following output.
INDEX KEY VALUE
0 testKey1 testValue1
1 testKey2 testValue2
2 keyToDelete valueToDelete
3 testKey3 testValue3
Displaying the entries of a modified OrderedDictionary.
INDEX KEY VALUE
0 insertedKey1 insertedValue1
1 testKey1 testValue1
2 testKey2 modifiedValue
Displaying the entries of a "new" OrderedDictionary.
KEY VALUE
newKey1 newValue1
newKey2 newValue2
newKey3 newValue3
*/
' The following code example enumerates the elements of a OrderedDictionary.
Imports System.Collections
Imports System.Collections.Specialized
Public Class OrderedDictionarySample
Public Shared Sub Main()
' Creates and initializes a OrderedDictionary.
Dim myOrderedDictionary As New OrderedDictionary()
myOrderedDictionary.Add("testKey1", "testValue1")
myOrderedDictionary.Add("testKey2", "testValue2")
myOrderedDictionary.Add("keyToDelete", "valueToDelete")
myOrderedDictionary.Add("testKey3", "testValue3")
Dim keyCollection As ICollection = myOrderedDictionary.Keys
Dim valueCollection As ICollection = myOrderedDictionary.Values
' Display the contents Imports the key and value collections
DisplayContents( _
keyCollection, valueCollection, myOrderedDictionary.Count)
' Modifying the OrderedDictionary
If Not myOrderedDictionary.IsReadOnly Then
' Insert a new key to the beginning of the OrderedDictionary
myOrderedDictionary.Insert(0, "insertedKey1", "insertedValue1")
' Modify the value of the entry with the key "testKey2"
myOrderedDictionary("testKey2") = "modifiedValue"
' Remove the last entry from the OrderedDictionary: "testKey3"
myOrderedDictionary.RemoveAt(myOrderedDictionary.Count - 1)
' Remove the "keyToDelete" entry, if it exists
If (myOrderedDictionary.Contains("keyToDelete")) Then
myOrderedDictionary.Remove("keyToDelete")
End If
End If
Console.WriteLine( _
"{0}Displaying the entries of a modified OrderedDictionary.", _
Environment.NewLine)
DisplayContents( _
keyCollection, valueCollection, myOrderedDictionary.Count)
' Clear the OrderedDictionary and add new values
myOrderedDictionary.Clear()
myOrderedDictionary.Add("newKey1", "newValue1")
myOrderedDictionary.Add("newKey2", "newValue2")
myOrderedDictionary.Add("newKey3", "newValue3")
' Display the contents of the "new" Dictionary Imports an enumerator
Dim myEnumerator As IDictionaryEnumerator = _
myOrderedDictionary.GetEnumerator()
Console.WriteLine( _
"{0}Displaying the entries of a 'new' OrderedDictionary.", _
Environment.NewLine)
DisplayEnumerator(myEnumerator)
End Sub
' Displays the contents of the OrderedDictionary from its keys and values
Public Shared Sub DisplayContents( _
ByVal keyCollection As ICollection, _
ByVal valueCollection As ICollection, ByVal dictionarySize As Integer)
Dim myKeys(dictionarySize) As [String]
Dim myValues(dictionarySize) As [String]
keyCollection.CopyTo(myKeys, 0)
valueCollection.CopyTo(myValues, 0)
' Displays the contents of the OrderedDictionary
Console.WriteLine(" INDEX KEY VALUE")
Dim i As Integer
For i = 0 To dictionarySize - 1
Console.WriteLine(" {0,-5} {1,-25} {2}", _
i, myKeys(i), myValues(i))
Next i
Console.WriteLine()
End Sub
' Displays the contents of the OrderedDictionary using its enumerator
Public Shared Sub DisplayEnumerator( _
ByVal myEnumerator As IDictionaryEnumerator)
Console.WriteLine(" KEY VALUE")
While myEnumerator.MoveNext()
Console.WriteLine(" {0,-25} {1}", _
myEnumerator.Key, myEnumerator.Value)
End While
End Sub
End Class
'This code produces the following output.
'
' INDEX KEY VALUE
'0: testKey1(testValue1)
'1: testKey2(testValue2)
'2: keyToDelete(valueToDelete)
'3: testKey3(testValue3)
'
'
'Displaying the entries of a modified OrderedDictionary.
' INDEX KEY VALUE
'0: insertedKey1(insertedValue1)
'1: testKey1(testValue1)
'2: testKey2(modifiedValue)
'
'
'Displaying the entries of a "new" OrderedDictionary.
' KEY(VALUE)
' newKey1(newValue1)
' newKey2(newValue2)
' newKey3(newValue3)
설명
각 요소는 개체에 저장된 키/값 쌍입니다 DictionaryEntry . 키는 될 null수 없지만 값은 될 수 있습니다.
클래스의 OrderedDictionary 요소와 달리 요소의 키는 키별로 SortedDictionary<TKey,TValue> 정렬되지 않습니다. 키 또는 인덱스로 요소에 액세스할 수 있습니다.
C# 언어의 foreach 문(Visual Basic For Each)은 컬렉션에 있는 각 요소의 형식인 개체를 반환합니다. 컬렉션의 OrderedDictionary 각 요소는 키/값 쌍이므로 요소 형식은 키의 형식이나 값의 형식이 아닙니다. 대신 요소 형식은 .입니다 DictionaryEntry. 다음 코드는 구문을 보여줍니다.
foreach (DictionaryEntry de in myOrderedDictionary)
{
//...
}
For Each de As DictionaryEntry In myOrderedDictionary
'...
Next de
이 foreach 문은 열거자 주위의 래퍼로, 컬렉션에서만 읽을 수 있으며, 컬렉션에 쓸 수 없습니다.
생성자
| Name | Description |
|---|---|
| OrderedDictionary() |
OrderedDictionary 클래스의 새 인스턴스를 초기화합니다. |
| OrderedDictionary(IEqualityComparer) |
지정된 비교자를 사용하여 클래스의 OrderedDictionary 새 인스턴스를 초기화합니다. |
| OrderedDictionary(Int32, IEqualityComparer) |
지정된 초기 용량 및 비교자를 사용하여 클래스의 OrderedDictionary 새 인스턴스를 초기화합니다. |
| OrderedDictionary(Int32) |
지정된 초기 용량을 사용하여 클래스의 OrderedDictionary 새 인스턴스를 초기화합니다. |
| OrderedDictionary(SerializationInfo, StreamingContext) |
지정된 개체와 StreamingContext 개체를 사용하여 직렬화할 수 있는 클래스의 OrderedDictionary 새 인스턴스를 SerializationInfo 초기화합니다. |
속성
| Name | Description |
|---|---|
| Count |
컬렉션에 포함된 OrderedDictionary 키/값 쌍의 수를 가져옵니다. |
| IsReadOnly |
컬렉션이 읽기 전용인지 여부를 OrderedDictionary 나타내는 값을 가져옵니다. |
| Item[Int32] |
지정된 인덱스에서 값을 가져오거나 설정합니다. |
| Item[Object] |
지정된 키를 가진 값을 가져오거나 설정합니다. |
| Keys |
컬렉션의 ICollection 키를 포함하는 개체를 OrderedDictionary 가져옵니다. |
| Values |
컬렉션의 ICollection 값을 포함하는 개체를 OrderedDictionary 가져옵니다. |
메서드
| Name | Description |
|---|---|
| Add(Object, Object) |
사용 가능한 인덱스가 가장 낮은 컬렉션에 OrderedDictionary 지정된 키와 값이 있는 항목을 추가합니다. |
| AsReadOnly() |
현재 OrderedDictionary 컬렉션의 읽기 전용 복사본을 반환합니다. |
| Clear() |
컬렉션에서 모든 요소를 제거합니다 OrderedDictionary . |
| Contains(Object) |
컬렉션에 OrderedDictionary 특정 키가 포함되어 있는지 여부를 확인합니다. |
| CopyTo(Array, Int32) |
지정된 인덱스의 OrderedDictionary 1차원 Array 개체에 요소를 복사합니다. |
| Equals(Object) |
지정한 개체와 현재 개체가 같은지 여부를 확인합니다. (다음에서 상속됨 Object) |
| GetEnumerator() |
IDictionaryEnumerator 컬렉션을 반복하는 개체를 OrderedDictionary 반환합니다. |
| GetHashCode() |
기본 해시 함수로 작동합니다. (다음에서 상속됨 Object) |
| GetObjectData(SerializationInfo, StreamingContext) |
인터페이스를 ISerializable 구현하고 컬렉션을 serialize하는 데 필요한 데이터를 반환합니다 OrderedDictionary . |
| GetType() |
현재 인스턴스의 Type 가져옵니다. (다음에서 상속됨 Object) |
| Insert(Int32, Object, Object) |
지정된 인덱스에 지정된 키와 값을 사용하여 컬렉션에 새 항목을 OrderedDictionary 삽입합니다. |
| MemberwiseClone() |
현재 Object단순 복사본을 만듭니다. (다음에서 상속됨 Object) |
| OnDeserialization(Object) |
인터페이스를 ISerializable 구현하고 역직렬화가 완료되면 역직렬화 이벤트에 의해 다시 호출됩니다. |
| Remove(Object) |
컬렉션에서 OrderedDictionary 지정된 키가 있는 항목을 제거합니다. |
| RemoveAt(Int32) |
컬렉션에서 지정된 인덱스의 항목을 제거합니다 OrderedDictionary . |
| ToString() |
현재 개체를 나타내는 문자열을 반환합니다. (다음에서 상속됨 Object) |
명시적 인터페이스 구현
| Name | Description |
|---|---|
| ICollection.IsSynchronized |
개체에 대한 액세스 OrderedDictionary 가 동기화되는지 여부를 나타내는 값을 가져옵니다(스레드로부터 안전). |
| ICollection.SyncRoot |
개체에 대한 액세스를 동기화하는 데 사용할 수 있는 개체를 OrderedDictionary 가져옵니다. |
| IDeserializationCallback.OnDeserialization(Object) |
인터페이스를 ISerializable 구현하고 역직렬화가 완료되면 역직렬화 이벤트에 의해 다시 호출됩니다. |
| IDictionary.IsFixedSize |
고정 크기가 있는지 여부를 OrderedDictionary 나타내는 값을 가져옵니다. |
| IEnumerable.GetEnumerator() |
IDictionaryEnumerator 컬렉션을 반복하는 개체를 OrderedDictionary 반환합니다. |
확장명 메서드
| Name | Description |
|---|---|
| AsParallel(IEnumerable) |
쿼리의 병렬 처리를 사용하도록 설정합니다. |
| AsQueryable(IEnumerable) |
IEnumerable IQueryable변환합니다. |
| Cast<TResult>(IEnumerable) |
IEnumerable 요소를 지정된 형식으로 캐스팅합니다. |
| OfType<TResult>(IEnumerable) |
지정된 형식에 따라 IEnumerable 요소를 필터링합니다. |