
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the Item property of Hashtable class in C#?
Gets or sets the value associated with the specified key. You can also use the Item property to add new elements.
If a key does not exist, then you can include it like −
myCollection["myNonexistentKey"] = myValue
The following is the code showing how to work with Item property of Hashtable class in C#.
Example
using System; using System.Collections; namespace Demo { class Program { static void Main(string[] args) { Hashtable ht = new Hashtable(); ht.Add("One", "Amit"); ht.Add("Two", "Aman"); ht.Add("Three", "Raman"); ht["Four"] = "David"; ICollection key = ht.Keys; foreach (string k in key) { Console.WriteLine(k + ": " + ht[k]); } Console.ReadKey(); } } }
Output
Three: Raman Four: David One: Amit Two: Aman
Advertisements