C# OrderedDictionary OrderedDictionary(Int32)

Description

OrderedDictionary OrderedDictionary(Int32) initializes a new instance of the OrderedDictionary class using the specified initial capacity.

Syntax

OrderedDictionary.OrderedDictionary(Int32) has the following syntax.


public OrderedDictionary(
  int capacity
)

Parameters

OrderedDictionary.OrderedDictionary(Int32) has the following parameters.

  • capacity - The initial number of elements that the OrderedDictionary collection can contain.

Example


using System;//ww  w. j ava2s.  co  m
using System.Collections;
using System.Collections.Specialized;

public class SamplesStringCollection  {

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

        ICollection keyCollection = myOrderedDictionary.Keys;
        ICollection valueCollection = myOrderedDictionary.Values;
        
        DisplayContents(keyCollection, valueCollection, myOrderedDictionary.Count);

   }
    public static void DisplayContents(ICollection keyCollection, ICollection valueCollection, int dictionarySize)
    {
        String[] myKeys = new String[dictionarySize];
        String[] myValues = new String[dictionarySize];
        keyCollection.CopyTo(myKeys, 0);
        valueCollection.CopyTo(myValues, 0);
    
        Console.WriteLine("   INDEX KEY                       VALUE");
        for (int i = 0; i < dictionarySize; i++)
        {
            Console.WriteLine("   {0,-5} {1,-25} {2}",
                i, myKeys[i], myValues[i]);
        }
    
    }

}

The code above generates the following result.





















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




BitVector32
HybridDictionary
ListDictionary
OrderedDictionary
StringCollection
StringDictionary
StringEnumerator