InterviewSolution
Saved Bookmarks
| 1. |
Usage of HashTable Collections in C# |
|
Answer» The HashTable Collection in C# is a collection of key-value pairs. These pairs are organised using the hash code of the KEYS. This means that when the elements need to be accessed in the HashTable, this can be DONE using keys. A program that demonstrates the HashTable Collection in C# is given as follows: using System; using System.Collections; namespace Demo { class Program { static void Main(string[] args) { Hashtable h = new Hashtable(); h.Add("1", "Apple"); h.Add("2", "Mango"); h.Add("3", "Orange"); h.Add("4", "Guava"); h.Add("5", "Peach"); h.Add("6", "Melon"); h.Add("7", "Lychee"); h.Add("8", "Cherry"); ICollection allKeys = h.Keys; foreach (string key in allKeys) { Console.WriteLine(key + ": " + h[key]); } } } }The output of the above program is given as follows: 1: Apple 6: Melon 7: Lychee 4: Guava 5: Peach 8: Cherry 2: Mango 3: Orange |
|