How to create a ListDictionary in C#
ListDictionary() constructor is used to initialize a new empty instance of the ListDictionary class using the default comparer. ListDictionary is a specialized collection. It comes under the System.Collections.Specialized namespace. This type represents a non-generic dictionary type. It is implemented with a linked list. This class is a simple implementation of a dictionary collection (System.Collections.IDictionary) for small lists.
Syntax:
public ListDictionary ();
Example 1:
// C# Program to illustrate how // to create a ListDictionary using System; using System.Collections; using System.Collections.Specialized; class Geeks { // Main Method public static void Main(String[] args) { // ld is the ListDictionary object // ListDictionary() is the constructor // used to initializes a new // instance of the ListDictionary class ListDictionary ld = new ListDictionary(); // Count property is used to get the // number of elements in ListDictionary // It will give 0 as no elements // are present currently Console.WriteLine("The number of elements: "+ ld.Count); } } |
The number of elements: 0
Example 2:
// C# Program to illustrate how // to create a ListDictionary using System; using System.Collections; using System.Collections.Specialized; class Geeks { // Main Method public static void Main(String[] args) { // ld is the ListDictionary object // ListDictionary() is the constructor // used to initializes a new // instance of the ListDictionary class ListDictionary ld = new ListDictionary(); Console.Write("Before Add Method: "); // Count property is used to get the // number of elements in ListDictionary // It will give 0 as no elements // are present currently Console.WriteLine(ld.Count); // Adding key/value pairs in ld ld.Add("Australia", "Canberra"); ld.Add("Belgium", "Brussels"); ld.Add("Netherlands", "Amsterdam"); ld.Add("China", "Beijing"); ld.Add("Russia", "Moscow"); ld.Add("India", "New Delhi"); Console.Write("After Add Method: "); // Count property is used to get the // number of elements in ld Console.WriteLine(ld.Count); } } |
Before Add Method: 0 After Add Method: 6
Reference:
Recommended Posts:
- C# | Add the specified key and value into the ListDictionary
- C# | Get or set the value associated with specified key in ListDictionary
- C# | ListDictionary Class
- C# | Get an ICollection containing the values in ListDictionary
- C# | Remove the entry with specified key from ListDictionary
- C# | Remove all entries from the ListDictionary
- How to get Synchronize access to the ListDictionary in C#
- C# | Get an ICollection containing the keys in ListDictionary
- C# | Check if ListDictionary contains a specific key
- C# | Get an enumerator that iterates through the ListDictionary
- C# | Check if ListDictionary is read-only
- C# | Check if two ListDictionary objects are equal
- C# | Get the number of key/value pairs contained in ListDictionary
- C# | Check if ListDictionary has a fixed size
- C# | Check if ListDictionary is synchronized (thread safe)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



