The HybridDictionary class implements IDictionary by using ListDictionary when the collection is small, and then switches to Hashtable when the collection becomes larger.
The following are the attributes of the HybridDictionary class:
Serial number | Attributes and description |
---|---|
1 |
Count Get the number of key/value pairs contained |
Gets a value indicating whether HybridDictionary has a fixed size.
Gets a value indicating whether the HybridDictionary is Read only.
Gets a value indicating whether the HybridDictionary is synchronized (thread safe).
Gets or sets the value associated with the specified key .
Get the ICollection containing the keys HybridDictionary.
Get objects available for synchronous access to HybridDictionary.
Get an ICollection of values contained in a HybridDictionary the HybridDictionary.
The following are some methods of the HybridDictionary class:
number | Method and Description |
---|---|
Add(Object, Object) Adds an entry with the specified key and value to the HybridDictionary. | |
Clear()Remove all entries from the HybridDictionary . | |
Contains(Object)Determines whether the HybridDictionary contains a specific key. | |
CopyTo(Array, Int32)Copy the entries of the HybridDictionary to a in a one-dimensional array The array instance at the specified index. | |
Equals(Object)Determines whether the specified object is equal to current object. (Inherited from Object) | |
GetEnumerator()Returns an IDictionaryEnumerator, used To traverse HybridDictionary. | |
GetHashCode() strong> Used as the default hash function. (Inherited from Object) | |
GetType() | Get the Type of the current instance . (Inherited from Object) |
Example
Now let us see some examples −
Demonstration
using System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main() { HybridDictionary dict1 = new HybridDictionary(); dict1.Add("A", "SUV"); dict1.Add("B", "MUV"); dict1.Add("C", "AUV"); Console.WriteLine("HybridDictionary1 elements..."); foreach(DictionaryEntry d in dict1) { Console.WriteLine(d.Key + " " + d.Value); } Console.WriteLine("Count of Key/value pairs in Dictionary1 = "+dict1.Count); HybridDictionary dict2 = new HybridDictionary(); dict2.Add("1", "One"); dict2.Add("2", "Two"); dict2.Add("3", "Three"); dict2.Add("4", "Four"); dict2.Add("5", "Five"); dict2.Add("6", "Six"); Console.WriteLine("HybridDictionary2 elements..."); foreach(DictionaryEntry d in dict2) { Console.WriteLine(d.Key + " " + d.Value); } Console.WriteLine("Count of Key/value pairs in Dictionary2 = "+dict1.Count); dict2.Clear(); Console.WriteLine("Count of Key/value pairs in Dictionary2 (Updated) = "+dict2.Count); } }
Output
This will produce the following output−
HybridDictionary1 elements... A SUV B MUV C AUV Count of Key/value pairs in Dictionary1 = 3 HybridDictionary2 elements... 1 One 2 Two 3 Three 4 Four 5 Five 6 Six Count of Key/value pairs in Dictionary2 = 3 Count of Key/value pairs in Dictionary2 (Updated) = 0
To check if the HybridDictionary is synchronized, The code is as follows −
Example
Real-time demonstration
using System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main() { HybridDictionary dict1 = new HybridDictionary(); dict1.Add("A", "Books"); dict1.Add("B", "Electronics"); dict1.Add("C", "Smart Wearables"); dict1.Add("D", "Pet Supplies"); dict1.Add("E", "Clothing"); dict1.Add("F", "Footwear"); Console.WriteLine("HybridDictionary1 elements..."); foreach(DictionaryEntry d in dict1) { Console.WriteLine(d.Key + " " + d.Value); } Console.WriteLine("Is the HybridDictionary1 having fixed size? = "+dict1.IsFixedSize); Console.WriteLine("If HybridDictionary1 read-only? = "+dict1.IsReadOnly); Console.WriteLine("Is HybridDictionary1 synchronized = "+dict1.IsSynchronized); HybridDictionary dict2 = new HybridDictionary(); dict2.Add("1", "One"); dict2.Add("2", "Two"); dict2.Add("3", "Three"); dict2.Add("4", "Four"); dict2.Add("5", "Five"); dict2.Add("6", "Six"); Console.WriteLine("HybridDictionary2 elements..."); foreach(DictionaryEntry d in dict2) { Console.WriteLine(d.Key + " " + d.Value); } Console.WriteLine("Is HybridDictionary1 equal to HybridDictionary2? = "+(dict1.Equals(dict2))); Console.WriteLine("Is the HybridDictionary2 having fixed size? = "+dict2.IsFixedSize); Console.WriteLine("If HybridDictionary2 read-only? = "+dict2.IsReadOnly); Console.WriteLine("Is HybridDictionary2 synchronized = "+dict2.IsSynchronized); } }
Output
This will produce the following output−
HybridDictionary1 elements... A Books B Electronics C Smart Wearables D Pet Supplies E Clothing F Footwear Is the HybridDictionary1 having fixed size? = False If HybridDictionary1 read-only? = False Is HybridDictionary1 synchronized = False HybridDictionary2 elements... 1 One 2 Two 3 Three 4 Four 5 Five 6 Six Is HybridDictionary1 equal to HybridDictionary2? = False Is the HybridDictionary2 having fixed size? = False If HybridDictionary2 read-only? = False Is HybridDictionary2 synchronized = False
The above is the detailed content of Mixed dictionary classes in C#?. For more information, please follow other related articles on the PHP Chinese website!

This article explores the challenges of NULL pointer dereferences in C. It argues that the problem isn't NULL itself, but its misuse. The article details best practices for preventing dereferences, including pre-dereference checks, pointer initiali

This article explains how to create newline characters in C using the \n escape sequence within printf and puts functions. It details the functionality and provides code examples demonstrating its use for line breaks in output.

This article guides beginners on choosing a C compiler. It argues that GCC, due to its ease of use, wide availability, and extensive resources, is best for beginners. However, it also compares GCC, Clang, MSVC, and TCC, highlighting their differenc

This article emphasizes the continued importance of NULL in modern C programming. Despite advancements, NULL remains crucial for explicit pointer management, preventing segmentation faults by marking the absence of a valid memory address. Best prac

This article reviews online C compilers for beginners, focusing on ease of use and debugging capabilities. OnlineGDB and Repl.it are highlighted for their user-friendly interfaces and helpful debugging tools. Other options like Programiz and Compil

This article compares online C programming platforms, highlighting differences in features like debugging tools, IDE functionality, standard compliance, and memory/execution limits. It argues that the "best" platform depends on user needs,

This article discusses efficient code copying in C IDEs. It emphasizes that copying is an IDE function, not a compiler feature, and details strategies for improved efficiency, including using IDE selection tools, code folding, search/replace, templa

This article troubleshoots missing output windows in C program compilation. It examines causes like failing to run the executable, program errors, incorrect compiler settings, background processes, and rapid program termination. Solutions involve ch


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
