OrderedDictionary.RemoveAt(Int32) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
從 OrderedDictionary 集合移除指定之索引處的元素。
public:
virtual void RemoveAt(int index);
public void RemoveAt (int index);
abstract member RemoveAt : int -> unit
override this.RemoveAt : int -> unit
Public Sub RemoveAt (index As Integer)
參數
- index
- Int32
要移除的項目之以零起始的索引。
實作
例外狀況
範例
下列程式代碼範例示範集合的 OrderedDictionary 修改。 在此範例中RemoveAtCount,方法會與 屬性搭配使用,以從 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 (!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
備註
在移除項目之後的專案會向上移動,以佔用空的現成位置,也會更新移動專案的索引。