OrderedDictionary.RemoveAt(Int32) Metod

Definition

Tar bort posten vid det angivna indexet OrderedDictionary från samlingen.

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)

Parametrar

index
Int32

Det nollbaserade indexet för posten som ska tas bort.

Implementeringar

Undantag

Samlingen OrderedDictionary är skrivskyddad.

index är mindre än noll.

-eller-

index är lika med eller större än Count.

Exempel

Följande kodexempel visar hur en OrderedDictionary samling har ändrats. I det här exemplet RemoveAt används metoden med Count egenskapen för att ta bort den sista posten från OrderedDictionary. Den här koden är en del av ett större kodexempel som kan visas på 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

Kommentarer

Posterna som följer den borttagna posten flyttas upp för att uppta den tömda platsen och indexen för de poster som flyttas uppdateras också.

Gäller för