PropertyCollection.IDictionary.Keys Propriété

Définition

Obtient un objet ICollection contenant les clés de l'objet IDictionary.

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

Valeur de propriété

Objet ICollection contenant les clés de l'objet IDictionary.

Implémente

Exemples

L’exemple suivant montre comment implémenter la Keys propriété. Cet exemple de code fait partie d’un exemple plus grand fourni pour la IDictionary classe .

public:
    virtual property ICollection^ Keys
    {
        ICollection^ get()
        {
            // Return an array where each item is a key.
            array<Object^>^ keys = gcnew array<Object^>(itemsInUse);
            for (int i = 0; i < itemsInUse; i++)
            {
                keys[i] = items[i]->Key;
            }
            return keys;
        }
    }
public ICollection Keys
{
    get
    {
        // Return an array where each item is a key.
        Object[] keys = new Object[ItemsInUse];
        for (Int32 n = 0; n < ItemsInUse; n++)
            keys[n] = items[n].Key;
        return keys;
    }
}
Public ReadOnly Property Keys() As ICollection Implements IDictionary.Keys
    Get

        ' 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

Remarques

L’ordre des clés dans l’objet retourné ICollection n’est pas spécifié, mais il est garanti qu’il s’agit du même ordre que les valeurs correspondantes dans le ICollection retourné par la Values propriété .

S’applique à

Voir aussi