C# | Get or set the value associated with the specified key in StringDictionary Last Updated : 01 Feb, 2019 Comments Improve Suggest changes Like Article Like Report StringDictionary is a specialized collection. It is found in 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. Below given are some examples to understand the implementation in a better way : Example 1: CSHARP // C# code to get or set the value // associated with the specified key // in StringDictionary using System; using System.Collections; using System.Collections.Specialized; class GFG { // Driver code public static void Main() { // Creating a StringDictionary named myDict StringDictionary myDict = new StringDictionary(); // Adding key and value into the StringDictionary myDict.Add("G", "GeeksforGeeks"); myDict.Add("C", "Coding"); myDict.Add("DS", "Data Structures"); myDict.Add("N", "Noida"); myDict.Add("GC", "Geeks Classes"); // Displaying the keys and values // in StringDictionary foreach(DictionaryEntry de in myDict) { Console.WriteLine(de.Key + " " + de.Value); } // To get the value corresponding to key "C" Console.WriteLine(myDict["C"]); // Changing the value corresponding to key "C" myDict["C"] = "C++"; // To get the value corresponding to key "C" Console.WriteLine(myDict["C"]); // To get the value corresponding to key "N" Console.WriteLine(myDict["N"]); // Changing the value corresponding to key "N" myDict["N"] = "North"; // To get the value corresponding to key "N" Console.WriteLine(myDict["N"]); // Displaying the keys and values // in StringDictionary foreach(DictionaryEntry de in myDict) { Console.WriteLine(de.Key + " " + de.Value); } } } Output: gc Geeks Classes c Coding n Noida ds Data Structures g GeeksforGeeks Coding C++ Noida North c C++ g GeeksforGeeks gc Geeks Classes ds Data Structures n North Comment More infoAdvertise with us Next Article C# | Get or set the value associated with the specified key in StringDictionary S Sahil_Bansall Follow Improve Article Tags : C# CSharp-Collections-Namespace CSharp-Specialized-StringDictionary CSharp-Specialized-Namespace Similar Reads C# | Gets or sets the value at the specified key in StringDictionary StringDictionary.Item[String] Property is used to get or set the value associated with the specified key. Syntax: public virtual string this[string key] { get; set; } Here, key is the Key of type System.String whose value is be to get or set. Return Value: This property returns the value associated 3 min read C# | Get or Set the value associated with specified key in Hashtable Hashtable.Item[Object] Property is used to get or set the value associated with the specified key in the Hashtable. Syntax: public virtual object this[object key] { get; set; } Here, key is key of object type whose value is to get or set. Exceptions: ArgumentNullException: If the key is null. NotSup 3 min read C# | Get or set the value associated with specified key in SortedList SortedList.Item[Object] Property is used to get and set the value associated with a specific key in a SortedList object. Syntax: public virtual object this[object key] { get; set; } Here, the key is associated with the value to get or set. It is of the object type. Return Value: This property return 4 min read C# | Get or set the value associated with specified key in ListDictionary ListDictionary.Item[Object] property is used to get or set the value associated with the specified key. Syntax: public object this[object key] { get; set; } Here, key is the key whose value to get or set. Return Value : The value associated with the specified key. If the specified key is not found, 2 min read C# | Get the number of key/value pairs in the StringDictionary StringDictionary.Count property is used to get the number of key/value pairs in the StringDictionary. Syntax: public virtual int Count { get; } Return Value: It returns the number of key/value pairs in the StringDictionary. Note: Retrieving the value of this property is an O(1) operation. Below prog 2 min read Like