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.
- NotSupportedException: If the property is set and the Hashtable is read-only. Or the property is set, key does not exist in the collection, and the Hashtable has a fixed size.
Note:
- This property returns the value associated with the specific key. If that key is not found, and one is trying to get that, then this property will return null and if trying to set, it will result into the creation of a new element with the specified key.
- Retrieving and setting the value of this property is an O(1) operation.
Below programs illustrate the use of above-discussed property:
Example 1:
Output:
d: data structures
c: c++
q: quiz
g: geeks
Updated Values:
d: data structures
c: C#
q: quiz
g: geeks
Example 2: