How to create an OrderedDictionary in C# Last Updated : 27 Feb, 2019 Improve Improve Like Article Like Save Share 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: // 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: // 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 Like Article Suggest improvement Previous C# | Gets or sets the value in HybridDictionary with specified key Next How to create a StringCollection in C# Share your thoughts in the comments Add Your Comment Please Login to comment...