
- 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
Gets an ICollection containing the values in the Hashtable in C#
To get an ICollection containing the values in the 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("A", "Electronics"); hash.Add("B", "Appliances"); hash.Add("C", "Pet Supplies"); hash.Add("D", "Books"); hash.Add("E", "Toys"); hash.Add("F", "Footwear"); hash.Add("G", "Clothing"); ICollection col = hash.Keys; foreach(string str in col) Console.WriteLine(str + ": " + hash[str]); } }
Output
This will produce the following output −
G: Clothing A: Electronics B: Appliances C: Pet Supplies D: Books E: Toys F: Footwear
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, "CD"); hash.Add(3, "EF"); hash.Add(4, "GH"); hash.Add(5, "IJ"); hash.Add(6, "KL"); hash.Add(7, "MN"); ICollection col = hash.Keys; foreach(int str in col) Console.WriteLine("Key = " + str + ", Value = " + hash[str]); } }
Output
This will produce the following output −
Key = 7, Value = MN Key = 6, Value = KL Key = 5, Value = IJ Key = 4, Value = GH Key = 3, Value = EF Key = 2, Value = CD Key = 1, Value = AB
- Related Articles
- Get an ICollection containing the keys in the Hashtable C#
- Get an ICollection containing the values in OrderedDictionary in C#
- Get an ICollection containing the values in ListDictionary in C#
- Get an ICollection containing the values in HybridDictionary in C#
- Get an ICollection containing the keys in HybridDictionary in C#
- Get an ICollection containing the keys in ListDictionary in C#
- Get an ICollection containing keys in OrderedDictionary in C#
- What is the Values property of Hashtable class in C#?
- How to add multiple values in the Hashtable using PowerShell?
- Adding an element into the Hashtable in C#
- What does the interface ICollection do in C#
- Copying the Hashtable elements to an Array Instance in C#
- Get an enumerator that iterates through the Hashtable in C#
- The HashTable Class in Javascript
- Python Pandas - Convert a MultiIndex to an Index of Tuples containing the level values

Advertisements