How to create a StringDictionary in C# Last Updated : 27 Feb, 2019 Comments Improve Suggest changes Like Article Like Report 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 keys and string values. It suffers from performance problems. It implements a hash table with the key and the value strongly typed to be strings rather than objects. Syntax: public StringDictionary (); Example 1: csharp // C# Program to illustrate how // to create a StringDictionary using System; using System.Collections; using System.Collections.Specialized; class Geeks { // Main Method public static void Main(String[] args) { // sd is the StringDictionary object // StringDictionary() is the constructor // used to initializes a new // instance of the StringDictionary class StringDictionary sd = new StringDictionary(); // Count property is used to get the // number of elements in StringDictionary // It will give 0 as no elements // are present currently Console.WriteLine(sd.Count); } } Output: 0 Example 2: csharp // C# Program to illustrate how // to create a StringDictionary using System; using System.Collections; using System.Collections.Specialized; class Geeks { // Main Method public static void Main(String[] args) { // sd is the StringDictionary object // StringDictionary() is the constructor // used to initializes a new // instance of the StringDictionary class StringDictionary sd = new StringDictionary(); Console.Write("Before Add Method: "); // Count property is used to get the // number of elements in StringDictionary // It will give 0 as no elements // are present currently Console.WriteLine(sd.Count); // Adding key/value pairs in sd sd.Add("1", "C"); sd.Add("2", "C++"); sd.Add("3", "Java"); sd.Add("4", "Python"); sd.Add("5", "C#"); sd.Add("6", "HTML"); Console.Write("After Add Method: "); // Count property is used to get the // number of elements in sd Console.WriteLine(sd.Count); } } Output: Before Add Method: 0 After Add Method: 6 Reference: https://docs.microsoft.com/en-us/dotnet/api/system.collections.specialized.stringdictionary.-ctor?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article How to create a StringDictionary in C# K Kirti_Mangal Follow Improve Article Tags : C# CSharp-Specialized-StringDictionary CSharp-Specialized-Namespace 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 StringCollection in C# StringCollection() constructor is used to initializing a new instance of the StringCollection class. StringCollection class is a new addition to the .NET Framework class library that represents a collection of strings. StringCollection class is defined in the System.Collections.Specialized namespace 2 min read How to create an OrderedDictionary in C# 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.Coll 2 min read How to create the StringBuilder in C# StringBuilder() constructor is used to initialize a new instance of the StringBuilder class which will be empty and will have the default initial capacity. StringBuilder is used to represent a mutable string of characters. Mutable means the string which can be changed. So String objects are immutabl 2 min read C# | Removing all entries from the StringDictionary StringDictionary.Clear method is used to remove all the entries from the StringDictionary. Syntax: public virtual void Clear (); Exception: This method will give the NotSupportedException if the StringDictionary is read-only. Example: CSHARP // C# code to remove all entries // from the StringDiction 2 min read C# StringDictionary Class In C#, the StringDictionary class is the part of the System.Collections.Specialized namespace. It is a collection of key-value pairs where the keys are strings and values are objects. It is similar to a Hashtable. But it is specifically designed for use with string keys.Keys are always strings, and 5 min read C# | Get a collection of keys in the StringDictionary StringDictionary.Keys property is used to get a collection of keys in the StringDictionary. Syntax: public virtual System.Collections.ICollection Keys { get; } Return Value: An ICollection that provides the keys in the StringDictionary. Below given are some examples to understand the implementation 2 min read How to get Synchronize access to the StringDictionary in C# StringDictionary.SyncRoot Property is used to get an object which can be used to synchronize access to the StringDictionary. It only allows string keys and string values. It suffers from performance problems. It implements a hash table with the key and the value strongly typed to be strings rather t 3 min read How to Compare Strings in C#? A string is a collection of characters and is used to store plain text. Unlike C or C++, a string in C# is not terminated with a null character. The maximum size of a string object depends on the internal architecture of the system. A variable declared followed by "string" is actually an object of s 13 min read C# | Get a collection of values in the StringDictionary StringDictionary.Values property is used to get a collection of values in the StringDictionary. Syntax: public virtual System.Collections.ICollection Values { get; } Return Value: An ICollection that provides the values in the StringDictionary. Example 1: CSHARP // C# code to get a collection // of 2 min read Like