How to create an OrderedDictionary in C# Last Updated : 27 Feb, 2019 Comments Improve Suggest changes Like Article Like Report OrderedDictionary() constructor is used to initialize a new instance of the OrderedDictionary class which will be empty and will have the default initial capacity. OrderedDictionary Class represents a collection of key/value pairs that are accessible by the key or index. It is present in System.Collections.Specialized namespace. Syntax: public OrderedDictionary(); Example 1: csharp // C# Program to illustrate how // to create a OrderedDictionary using System; using System.Collections; using System.Collections.Specialized; class Geeks { // Main Method public static void Main(String[] args) { // od is the OrderedDictionary object // OrderedDictionary() is the constructor // used to initializes a new // instance of the OrderedDictionary class OrderedDictionary od = new OrderedDictionary(); // Count property is used to get the // number of elements in OrderedDictionary // It will give 0 as no elements // are present currently Console.WriteLine("The number of elements: " +od.Count); } } Output: The number of elements: 0 Example 2: csharp // C# Program to illustrate how // to create a OrderedDictionary using System; using System.Collections; using System.Collections.Specialized; class Geeks { // Main Method public static void Main(String[] args) { // od is the OrderedDictionary object // OrderedDictionary() is the constructor // used to initializes a new // instance of the OrderedDictionary class OrderedDictionary od = new OrderedDictionary(); Console.Write("Before Add Method: "); // Count property is used to get the // number of elements in OrderedDictionary // It will give 0 as no elements // are present currently Console.WriteLine(od.Count); // Adding key/value pairs in od od.Add("1", "C"); od.Add("2", "C++"); od.Add("3", "Java"); od.Add("4", "C#"); Console.Write("After Add Method: "); // Count property is used to get the // number of elements in ld Console.WriteLine(od.Count); } } Output: Before Add Method: 0 After Add Method: 4 Reference: https://docs.microsoft.com/en-us/dotnet/api/system.collections.specialized.ordereddictionary.-ctor?view=netframework-4.7.2#System_Collections_Specialized_OrderedDictionary__ctor Comment More infoAdvertise with us Next Article How to create an OrderedDictionary in C# K Kirti_Mangal Follow Improve Article Tags : C# CSharp-Specialized-Namespace CSharp-Specialized-OrderedDictionary Similar Reads 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 implement 2 min read How to create a StringDictionary in C# StringDictionary() constructor is used to initialize a new instance of the StringDictionary class which will be empty and will have the default initial capacity. StringDictionary is a specialized collection. This class comes under the System.Collections.Specialized namespace. It only allows string k 2 min read C# | Get a read-only copy of the OrderedDictionary OrderedDictionary.AsReadOnly method returns a read-only copy of the current OrderedDictionary collection. Syntax: public System.Collections.Specialized.OrderedDictionary AsReadOnly (); Return Value: A read-only copy of the current OrderedDictionary collection. Below given are some examples to unders 2 min read C# | How to create a SortedList SortedList class is a collection of (key, value) pairs which are sorted according to keys. Those pairs can be accessible by key and as well as by index(zero-based indexing). This comes under System.Collections namespace. Properties of SortedList: Internally the object of SortedList maintains two arr 2 min read C# | How to create a SortedSet SortedSet class represents the collection of objects in sorted order. This class comes under the System.Collections.Generic namespace. Properties : In C#, SortedSet class can be used to store, remove or view elements. It maintains ascending order and does not store duplicate elements. It is suggeste 2 min read Like