how to use HASHTABLE in .net with example

Posted by Sekar.C under C# on 4/17/2012 | Points: 10 | Views : 69374 | Status : [Member] | Replies : 6
Hi,
how to use HASHTABLE in .net with example

Regards
Sekar.c



Responses

Posted by: Sunny4989 on: 4/17/2012 [Member] Starter | Points: 25

Up
0
Down
HashTable stores a key-value pair type collection of data.

Declaration:

Dim sampleHt as Hashtable = New Hashtable
sampleHt.add("Area",1000)
sampleHt.add("Perimeter",55)

NOTE:

Both key and value are object

We can retrieve the items from the hashtable by providing the key.

------------------------------------------------
Learn throughout life

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

Posted by: Sridevi on: 4/17/2012 [Member] Starter | Points: 25

Up
0
Down
Using hashtable we can acheive data uniqueness in C#. Data uniqueness means without having null values and duplicate data.

EXAMPLE:


Hashtable h=new Hashtable();
h.add("a","one");
h.add("b","two");
h.add("c","three");

TO RETREIVE:
Dictionary entry is an interface used to retrieve the data present inside the hashtable.

EXAMPLE
foreach(DictionaryEntry d in h)
{
console.writeline(d.key);
console.writeline(d.value);
}

Regards,
Sridevi.

Sridevi

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

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

Up
0
Down
follow the link , it shows all functions reagrding hashtable with full source code

http://csharp.net-informations.com/collection/csharp-hashtable.htm

nicol


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

Posted by: Prabhukiran345 on: 4/18/2013 [Member] Starter | Points: 25

Up
0
Down
In simple Hashtable is that which optimizes Searching criteria. That means a person having Surname.. In a group of people a person can easily been identified with his Surname.In the same manner Hash table contains Key,Value pairs which helps for optimizing Lookup's.
Lookup means: A procedure which a value is been searched until it is found.
Items in Hashtable are added with Add() method.

Example in c#::
Hashtable hashtable = new Hashtable();
hashtable[1] = "One";
hashtable[2] = "Two";
hashtable[13] = "Thirteen";

foreach (DictionaryEntry entry in hashtable)
{
Console.WriteLine("{0}, {1}", entry.Key, entry.Value);
}

Thanks,
Prabhu Kiran Bommareddy

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

Login to post response