C# | Creating an empty case-sensitive HybridDictionary Class
Last Updated :
16 Nov, 2022
HybridDictionary() creates an empty case-sensitive HybridDictionary. Syntax:
public HybridDictionary ();
Below given are some examples to understand the implementation in a better way: Example 1:
CSHARP
using System;
using System.Collections;
using System.Collections.Specialized;
class GFG {
public static void Main()
{
HybridDictionary myDict = new HybridDictionary();
myDict.Add("I", "first");
myDict.Add("II", "second");
myDict.Add("III", "third");
myDict.Add("IV", "fourth");
myDict.Add("V", "fifth");
foreach (DictionaryEntry de in myDict)
Console.WriteLine(de.Key + " " + de.Value);
}
}
|
Output:
I first
II second
III third
IV fourth
V fifth
Example 2:
CSHARP
using System;
using System.Collections;
using System.Collections.Specialized;
class GFG {
public static void Main()
{
HybridDictionary myDict = new HybridDictionary();
myDict.Add("A", "Apple");
myDict.Add("a", "Air");
myDict.Add("B", "Banana");
myDict.Add("C", "Cat");
myDict.Add("D", "Dog");
myDict.Add("d", "Dolphine");
myDict.Add("E", "Elephant");
myDict.Add("F", "Fish");
foreach (DictionaryEntry de in myDict)
Console.WriteLine(de.Key + " " + de.Value);
}
}
|
Output:
A Apple
a Air
B Banana
C Cat
D Dog
d Dolphin
E Elephant
F Fish
Note:
- By default, the collection is case-sensitive.
- The comparer determines whether two keys are equal. Every key in a HybridDictionary must be unique.
- This constructor is an O(1) operation.
Reference:
- https://docs.microsoft.com/en-us/dotnet/api/system.collections.specialized.hybriddictionary.-ctor?view=netframework-4.7.2#System_Collections_Specialized_HybridDictionary__ctor
Share your thoughts in the comments
Please Login to comment...