Creating a HybridDictionary with specified initial size in C#


To create a HybridDictionary with specified initial size, the code is as follows −

Example

 Live Demo

using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
   public static void Main(){
      HybridDictionary dict = new HybridDictionary(5);
      dict.Add("A", "AB");
      dict.Add("B", "BC");
      dict.Add("C", "DE");
      dict.Add("D", "FG");
      dict.Add("E", "HI");
      Console.WriteLine("Key/Value pairs...");
      foreach(DictionaryEntry d in dict)
      Console.WriteLine("Key = "+d.Key + ", Value = " + d.Value);
   }
}

Output

This will produce the following output −

Key/Value pairs...
Key = A, Value = AB
Key = B, Value = BC
Key = C, Value = DE
Key = D, Value = FG
Key = E, Value = HI

Example

Let us now see another example −

 Live Demo

using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
   public static void Main(){
      HybridDictionary dict = new HybridDictionary(10);
      dict.Add("1", 100);
      dict.Add("2", 200);
      dict.Add("3", 300);
      dict.Add("4", 400);
      dict.Add("5", 500);
      dict.Add("6", 600);
      dict.Add("7", 700);
      dict.Add("8", 800);
      dict.Add("9", 900);
      dict.Add("10", 1000);
      Console.WriteLine("Key/Value pairs...");
      foreach(DictionaryEntry d in dict)
      Console.WriteLine("Key = "+d.Key + ", Value = " + d.Value);
   }
}

Output

This will produce the following output −

Key/Value pairs...
Key = 10, Value = 1000
Key = 1, Value = 100
Key = 2, Value = 200
Key = 3, Value = 300
Key = 4, Value = 400
Key = 5, Value = 500
Key = 6, Value = 600
Key = 7, Value = 700
Key = 8, Value = 800
Key = 9, Value = 900

Updated on: 05-Dec-2019

56 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements