Creating a HybridDictionary with specified initial size in C#

CsharpServer Side ProgrammingProgramming

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
raja
Published on 05-Dec-2019 10:57:59
Advertisements