
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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
- Related Articles
- What is the Count property of Hashtable class in C#?
- What is the Values property of Hashtable class in C#?
- What is the IsReadOnly property of Hashtable class in C#?
- What is the Keys property of Hashtable class in C#?
- What is the IsFixedSize property of Hashtable class in C#?
- What is the Item property of BitArray class in C#?
- What is the Item property of ArrayList class in C#?
- What is the Item property of SortedList class in C#?
- What is the Hashtable class in C#?
- Remove an item from a Hashtable in C#
- What is the Count property of ArrayList class in C#?
- What is the Capacity property of SortedList class in C#?
- What is the Count property of BitArray class in C#?
- What is the Count property of Queue class in C#?
- What is the Count property of Stack class in C#?

Advertisements