- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get or Set the value associated with specified key in Hashtable in C#
To get or set the value associated with specified key in Hashtable, the code is as follows −
Example
using System; using System.Collections; public class Demo { public static void Main() { Hashtable hash = new Hashtable(); hash.Add("1", "AB"); hash.Add("2", "BC"); hash.Add("3", "DE"); hash.Add("4", "EF"); hash.Add("5", "GH"); hash.Add("6", "IJ"); hash.Add("7", "KL"); hash.Add("8", "MN"); hash.Add("9", "OP"); hash.Add("10", "QR"); Console.WriteLine("Value at key 3 = "+hash["3"]); } }
Output
This will produce the following output −
Value at key 3 = DE
Example
Let us see another example −
using System; using System.Collections; public class Demo { public static void Main() { Hashtable hash = new Hashtable(); hash.Add("1", "AB"); hash.Add("2", "BC"); hash.Add("3", "DE"); hash.Add("4", "EF"); hash.Add("5", "GH"); hash.Add("6", "IJ"); hash.Add("7", "KL"); hash.Add("8", "MN"); hash.Add("9", "OP"); hash.Add("10", "QR"); Console.WriteLine("Value at key 3 = "+hash["3"]); hash["3"] = "UV"; Console.WriteLine("Value at key 3 (UPDATED) = "+hash["3"]); } }
Output
This will produce the following output −
Value at key 3 = DE Value at key 3 (UPDATED) = UV
- Related Articles
- Get or set the value associated with specified key in ListDictionary in C#
- Get or set the value associated with specified key in SortedList in C#
- Get or set the value associated with the specified key in StringDictionary in C#
- Remove the element with the specified key from the Hashtable in C#
- Get the value associated with a given key in Java HashMap
- Gets or sets the value in HybridDictionary with specified key in C#
- How to get hash code for the specified key of a Hashtable in C#?
- Gets or sets the value at the specified key in StringDictionary in C#
- Get or Set at specified index in StringCollection in C#
- Get or set the element at specified index in Collection in C#
- Modify the value associated with a given key in Java HashMap
- Count the number of key/value pairs in the Hashtable in C#
- Get or set the element at the specified index in ArrayList in C#
- How to get the value associated with the http-equiv or name attribute in HTML?
- Insert into OrderedDictionary with key and value at specified index in C#

Advertisements