PropertyCollection.IDictionary.Keys Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Gets an ICollection object containing the keys of the IDictionary object.

Namespace:   System.DirectoryServices
Assembly:  System.DirectoryServices (in System.DirectoryServices.dll)

Private ReadOnly Property Keys As ICollection Implements IDictionary.Keys

Property Value

Type: System.Collections.ICollection

An ICollection object containing the keys of the IDictionary object.

The order of the keys in the returned ICollection object is unspecified, but is guaranteed to be the same order as the corresponding values in the ICollection returned by the Values property.

The following example shows how to implement the Keys property. This code example is part of a larger example provided for the IDictionary class.

Public ReadOnly Property Keys() As ICollection Implements IDictionary.Keys

        ' Return an array where each item is a key.
        ' Note: Declaring keyArray() to have a size of ItemsInUse - 1
        '       ensures that the array is properly sized, in VB.NET
        '       declaring an array of size N creates an array with
        '       0 through N elements, including N, as opposed to N - 1
        '       which is the default behavior in C# and C++.
        Dim keyArray() As Object = New Object(ItemsInUse - 1) {}
        Dim n As Integer
        For n = 0 To ItemsInUse - 1
            keyArray(n) = items(n).Key
        Next n

        Return keyArray
    End Get
End Property

.NET Framework
Available since 2.0
Return to top