OrderedDictionary.Keys 속성

정의

ICollection 컬렉션의 키가 포함된 OrderedDictionary 개체를 가져옵니다.

public:
 property System::Collections::ICollection ^ Keys { System::Collections::ICollection ^ get(); };
public System.Collections.ICollection Keys { get; }
member this.Keys : System.Collections.ICollection
Public ReadOnly Property Keys As ICollection

속성 값

ICollection 컬렉션의 키가 포함된 OrderedDictionary 개체입니다.

구현

예제

다음 코드 예제에서는 컬렉션의 생성 및 채우기를 OrderedDictionary 보여 줍니다. 그런 다음 콘텐츠를 콘솔에 인쇄합니다. 이 예제에서 KeysValues 속성은 내용을 표시하는 메서드에 전달됩니다. 이 코드는 에서 OrderedDictionary볼 수 있는 더 큰 코드 예제의 일부입니다.

// Creates and initializes a OrderedDictionary.
OrderedDictionary^ myOrderedDictionary = gcnew 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);
// 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);
' 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)
// Displays the contents of the OrderedDictionary from its keys and values
static void DisplayContents(
    ICollection^ keyCollection, ICollection^ valueCollection, int dictionarySize)
{
    array<String^>^ myKeys = gcnew array<String^>(dictionarySize);
    array<String^>^ myValues = gcnew array<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 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 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

설명

반환 ICollection 된 개체는 정적 복사본이 아니며, 대신 는 ICollection 원래 OrderedDictionary 컬렉션의 키를 다시 참조합니다. 따라서 에 대한 OrderedDictionary 변경 내용은 에 계속 반영됩니다 ICollection.

적용 대상