共用方式為


IDictionary.Keys 屬性

定義

取得 ICollection 包含該 IDictionary 物件鍵的物件。

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 包含該 IDictionary 物件鍵的物件。

範例

以下程式碼範例示範如何實作該 Keys 屬性。 此程式碼範例是本類別更大範例 IDictionary 的一部分。

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順序相同。

適用於

另請參閱