通过


OrderedDictionary.Count 属性

定义

获取集合中包含的 OrderedDictionary 键/值对的数目。

public:
 property int Count { int get(); };
public int Count { get; }
member this.Count : int
Public ReadOnly Property Count As Integer

属性值

集合中包含的 OrderedDictionary 键/值对数。

实现

示例

下面的代码示例演示集合的 OrderedDictionary 修改。 在此示例中,该 Count 属性用于删除该 OrderedDictionary属性中的最后一项。 此代码是可在以下位置 OrderedDictionary查看的较大代码示例的一部分。

// Modifying the OrderedDictionary
if (!myOrderedDictionary.IsReadOnly)
{
    // Insert a new key to the beginning of the OrderedDictionary
    myOrderedDictionary.Insert(0, "insertedKey1", "insertedValue1");

    // Modify the value of the entry with the key "testKey2"
    myOrderedDictionary["testKey2"] = "modifiedValue";

    // Remove the last entry from the OrderedDictionary: "testKey3"
    myOrderedDictionary.RemoveAt(myOrderedDictionary.Count - 1);

    // Remove the "keyToDelete" entry, if it exists
    if (myOrderedDictionary.Contains("keyToDelete"))
    {
        myOrderedDictionary.Remove("keyToDelete");
    }
}
' Modifying the OrderedDictionary
If Not myOrderedDictionary.IsReadOnly Then

    ' Insert a new key to the beginning of the OrderedDictionary
    myOrderedDictionary.Insert(0, "insertedKey1", "insertedValue1")

    ' Modify the value of the entry with the key "testKey2"
    myOrderedDictionary("testKey2") = "modifiedValue"

    ' Remove the last entry from the OrderedDictionary: "testKey3"
    myOrderedDictionary.RemoveAt(myOrderedDictionary.Count - 1)

    ' Remove the "keyToDelete" entry, if it exists
    If (myOrderedDictionary.Contains("keyToDelete")) Then
        myOrderedDictionary.Remove("keyToDelete")
    End If
End If

适用于