PropertyCollection.IDictionary.Keys プロパティ

定義

ICollection オブジェクトのキーを保持している IDictionary オブジェクトを取得します。Gets an ICollection object containing the keys of the IDictionary object.

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

プロパティ値

ICollection オブジェクトのキーを保持している IDictionary オブジェクト。An ICollection object containing the keys of the IDictionary object.

実装

次の例は、 Keysプロパティを実装する方法を示しています。The following example shows how to implement the Keys property. このコード例は、 IDictionaryクラスに対して提供される大規模な例の一部です。This code example is part of a larger example provided for the IDictionary class.

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

注釈

返さICollectionれたオブジェクト内のキーの順序は指定されていませんが、 ValuesプロパティによってICollection返される内の対応する値と同じ順序であることが保証されています。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.

適用対象

こちらもご覧ください