C# | Gets or sets the value in HybridDictionary with specified key Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report 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 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. Below programs illustrate the use of HybridDictionary.Item[Object] property: Example 1: CSHARP // C# code to get or set the value // associated with the specified key // in HybridDictionary using System; using System.Collections; using System.Collections.Specialized; class GFG { // Driver code public static void Main() { // Creating a HybridDictionary named myDict HybridDictionary myDict = new HybridDictionary(); // 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. Retrieving the value of this property is an O(1) operation. Setting the property is also an O(1) operation. Reference: https://learn.microsoft.com/en-us/dotnet/api/system.collections.specialized.hybriddictionary.item?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article C# | Removing the specified key entry from HybridDictionary S Sahil_Bansall Follow Improve Article Tags : C# CSharp-Specialized-Namespace CSharp-Specialized-HybridDictionary Similar Reads 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 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# | Adding the specified key and value into HybridDictionary HybridDictionary.Add(Object, Object) method is used to add an entry with the specified key and value into the HybridDictionary. 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: 3 min read C# | Count the number of key/value pairs in HybridDictionary HybridDictionary.Count property is used to get the number of key/value pairs contained in the HybridDictionary. Syntax: public int Count { get; } Return Value: The number of key/value pairs contained in the HybridDictionary. Note: Retrieving the value of this property is an O(1) operation. Below pro 2 min read C# | Removing the specified key entry from HybridDictionary HybridDictionary.Remove(Object) method is used to remove the entry with the specified key from the HybridDictionary. Syntax: public void Remove (object key); Here, key is the key of the entry to remove. Exception: This method throws ArgumentNullException if the key is null. Below given are some exam 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 Like