Regarding the hash table in asp.net

Posted by Bhasker under Regular Expressions on 9/7/2010 | Points: 10 | Views : 3631 | Status : [Member] | Replies : 3
dear all
how we are using hash table in cs file and then making object of hash table in aspx.cs file and perform the different functionality like
ADD,REMOVE......
pl describe in details and purpose.
thanks




Responses

Posted by: Abhi2434 on: 9/7/2010 [Member] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
HashTable is Old, you should use Dictionary.

It is generic and allows you to minimize Boxing.

Dictionary<type1,type2> d = new Dictionary<type1,type2>();

d.Add(...)

d.Remove(... )

Dictionary is an array of KeyValuePair.

www.abhisheksur.com

Bhasker, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Poster on: 9/7/2010 [Member] Starter | Points: 25

Up
0
Down
Hashtable comes under System.Collections namespace and is used to store the objects in Key and Value pairs.

Below is the code snippet to add and remove the objects from the Hashtable

Hashtable hTable = new Hashtable();
hTable.Add("d", "FDASFASD"); // can any type of object
hTable.Add("e", 1);

// remove the object
hTable.Remove("e");
hTable.Remove("DD"); // even if "DD" key doesn't exsits, it will not throw any error


Hope this will help you.

Thanks

Bhasker, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vinay13mar on: 10/27/2012 [Member] Starter | Points: 25

Login to post response