Is there any way to add integer elements into HashTable? If Hashtable named as h1.
Like h1.Add(10);h1.Add(20);h1.Add(30);
But i studied about Hashtable has two fields key and value pair.But i need to know can we add items into hashtable like Arraylist or List?If i add only one item into hashtable it shows an error.Is there any other way to add only integer elements into Hashtable?If i can do that how will i retrieve hashtable items?Please help me to clear my problem.
Thanks.
jaguRitaPosted Aug 8, 2007, 10:08 AM
Munir ShaikhPosted Aug 8, 2007, 4:39 AM
Check this URL you will get more depth in hashtable
http://www.c-sharpcorner.com/UploadFile/munnamax/whoseonline08042007062609AM/whoseonline.aspx
Regards,
>>Munnamax
AlanPosted Aug 8, 2007, 4:08 AM
Yes, you can add integers or any other type of object to a Hashtable. However, you have to provide a key for each value you add. The key / values pairs are stored internally in DictionaryEntry objects which have Key and Value properties to enable them to be easily retrieved. For example:
Hashtable ht = new Hashtable();
ht.Add("Ten", 10); // the first argument is the key
ht.Add("Twenty", 20);
ht.Add("Thirty",30);
foreach (DictionaryEntry de in ht )
Console.WriteLine("{0}, {1}",de.Key, de.Value);