OrderedDictionary.Keys Property
.NET Framework (current version)
Gets an ICollection object containing the keys in the OrderedDictionary collection.
Assembly: System (in System.dll)
Property Value
Type: System.Collections.ICollectionAn ICollection object containing the keys in the OrderedDictionary collection.
Implements
IDictionary.KeysThe returned ICollection object is not a static copy; instead, the ICollection refers back to the keys in the original OrderedDictionary collection. Therefore, changes to the OrderedDictionary continue to be reflected in the ICollection.
The following code example demonstrates the creation and population of an OrderedDictionary collection, and then prints the contents to the console. In this example, the Keys and Values properties are passed to a method that displays the contents. This code is part of a larger code example that can be viewed at OrderedDictionary.
' 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 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
Universal Windows Platform
Available since 10
.NET Framework
Available since 2.0
Available since 10
.NET Framework
Available since 2.0
Show: