Specified Key से Associated Value को Gets या Sets करता है। नए Elements Add करने के लिए भी Item Property का उपयोग कर सकते हैं।
यदि Key Exist नहीं करती, तो आप इसे ऐसे Include कर सकते हैं:
myCollection["myNonexistentKey"] = myValue
निम्न Code दर्शाता है कि C# में Hashtable Class की Item Property के साथ कैसे काम करें।
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