C# | Get or set the value associated with specified key in ListDictionary Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report 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, attempting to get it returns null, and attempting to set it creates a new entry using the specified key. Exception: This property will give ArgumentNullException if the key is null. Example: CSHARP // C# code to get or set the value // associated with the specified key using System; using System.Collections; using System.Collections.Specialized; class GFG { // Driver code public static void Main() { // Creating a ListDictionary named myDict ListDictionary myDict = new ListDictionary(); // Adding key/value pairs in myDict myDict.Add("Australia", "Canberra"); myDict.Add("Belgium", "Brussels"); myDict.Add("Netherlands", "Amsterdam"); myDict.Add("China", "Beijing"); myDict.Add("Russia", "Moscow"); myDict.Add("India", "New Delhi"); // Displaying the key/value pairs in myDict foreach(DictionaryEntry de in myDict) { Console.WriteLine(de.Key + " " + de.Value); } // Displaying the value associated // with key "Russia" Console.WriteLine(myDict["Russia"]); // Setting the value associated with key "Russia" myDict["Russia"] = "Saint Petersburg"; // Displaying the value associated // with key "Russia" Console.WriteLine(myDict["Russia"]); // Displaying the value associated // with key "India" Console.WriteLine(myDict["India"]); // Setting the value associated with key "India" myDict["India"] = "Mumbai"; // Displaying the value associated // with key "India" Console.WriteLine(myDict["India"]); // Displaying the key/value pairs in myDict foreach(DictionaryEntry de in myDict) { Console.WriteLine(de.Key + " " + de.Value); } } } Output: Australia Canberra Belgium Brussels Netherlands Amsterdam China Beijing Russia Moscow India New Delhi Moscow Saint Petersburg New Delhi Mumbai Australia Canberra Belgium Brussels Netherlands Amsterdam China Beijing Russia Saint Petersburg India Mumbai Note: This property provides the ability to access a specific element in the collection by using the syntax : myCollection[key]. A key cannot be null, but a value can. This method is an O(n) operation, where n is Count. Reference: https://learn.microsoft.com/en-us/dotnet/api/system.collections.specialized.listdictionary.item?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article C# | Gets or sets the value in HybridDictionary with specified key S Sahil_Bansall Follow Improve Article Tags : C# CSharp-Specialized-Namespace CSharp-Specialized-ListDictionary Similar Reads 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 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 the specified key in StringDictionary 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 2 min read C# | Gets or sets the value in HybridDictionary with specified key HybridDictionary.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 is to be get or set. Return Value: The value associated with the specified key. If the specified key is not 2 min read C# | Gets or sets the value in HybridDictionary with specified key HybridDictionary.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 is to be get or set. Return Value: The value associated with the specified key. If the specified key is not 2 min read C# | Add the specified key and value into the ListDictionary ListDictionary.Add(Object, Object) method is used to add an entry with the specified key and value into the ListDictionary. Syntax: public void Add (object key, object value); Parameters: key : The key of the entry to add. value : The value of the entry to add. The value can be null. Exceptions: Arg 2 min read Like