C# OrderedDictionary Insert

Description

OrderedDictionary Insert inserts a new entry into the OrderedDictionary collection with the specified key and value at the specified index.

Syntax

OrderedDictionary.Insert has the following syntax.


public void Insert(
  int index,//  w ww  . j a v  a  2s.c  om
  Object key,
  Object value
)

Parameters

OrderedDictionary.Insert has the following parameters.

  • index - The zero-based index at which the element should be inserted.
  • key - The key of the entry to add.
  • value - The value of the entry to add. The value can be null.

Returns

OrderedDictionary.Insert method returns

Example


using System;// www  .j a v  a2 s .  c o  m
using System.Collections;
using System.Collections.Specialized;

public class SamplesStringCollection  {

   public static void Main()  {
        OrderedDictionary myOrderedDictionary = new OrderedDictionary();
        myOrderedDictionary.Add("testKey1", "testValue1");
        myOrderedDictionary.Add("testKey2", "testValue2");
        myOrderedDictionary.Add("testKey3", "testValue3");


        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");
        }

   }
}




















Home »
  C# Tutorial »
    System.Collections.Specialized »




BitVector32
HybridDictionary
ListDictionary
OrderedDictionary
StringCollection
StringDictionary
StringEnumerator