C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » .NET »

HashTable


Posted Date: 24 Sep 2008      Posted By: sathish      Member Level: Silver     Points: 1   Responses: 5



What to Mean by HashTable




Responses

Author: krish    24 Sep 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 5

The Hashtable object contains items in key/value pairs. The keys are used as indexes, and very quick searches can be made for values by searching through their keys.

Items are added to the Hashtable with the Add() method.

The following code creates a Hashtable named mycountries and four elements are added:

<script runat="server">
Sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New Hashtable
mycountries.Add("N","Norway")
mycountries.Add("S","Sweden")
mycountries.Add("F","France")
mycountries.Add("I","Italy")
end if
end sub
</script>



Author: Geetha    24 Sep 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 6

The Hashtable object contains items in key/value pairs. The keys are used as indexes. We can search value by using their corresponding key. Items are added to the Hashtable with the Add() method. The data type of Hashtable is object and the default size of a Hashtable is 16.
The objects used as keys must implement Object.Equals and Object.GetHashCode methods.

private Hashtable table = new Hashtable();

public void AddEntry(BookEntry entry)
{
table.Add( entry.GetPerson(), entry );
}

Once the hash table is populated, you can search and retrieve elements in it by calling the indexer for the Hashtable class.

public BookEntry GetEntry(Person key)
{
return (BookEntry) table[key];
}

Entries can be removed from the hash table by calling the Remove method which takes a key identifying the element you want to remove.

public void DeleteEntry(Person key)
{
table.Remove( key );
}



Author: karthikeyan-The Great    24 Sep 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 5

Hast table is a data structure that associates keys with values. The primary operation it supports efficiently is a lookup: given a key (e.g. a person's name), find the corresponding value (e.g. that person's telephone number). It works by transforming the key using a hash function into a hash, a number that is used as an index in an array to locate the desired location ("bucket") where the values should be.


Author: Sherrie    24 Sep 2008Member Level: SilverRating: 2 out of 52 out of 5     Points: 6

Represents a collection of key-and-value pairs that are organized based on the hash code of the key.
Constructor of HashTable
We have ten overloaded Contructor. we will see some important constructors of HashTable.
Constructor with no parameters - Creates an empty HashTable.
Constructor with an Integer Parameter - Creates an empty hashtable, where the parameter represents the approximate number of element that the HashTable can have initially.
Adding an element to the HashTable
Adding an element to the hash table is very simple. It is done through Add method which takes the two parameter key and the value. Where the key represents the key which will be used to access the element and value is of type object which is the actual element to tbe stored.
http://www.dotnetspider.com/resources/279-Working-wi-HashTable.aspx



Author: Sabu C Alex    25 Sep 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 5

Hash table is like an arraylist. But the difference is Hashtable stores values in Key value pair format
tht is you have to pass a key with a value. So that u can access that value by passing that key.

eg:
HashTable ht = new HashTable();
ht.Add("Key1","Sabu");
ht.Add("Key2","Shine");
ht.Add("Key3","Binu");
ht.Add("Key4","JK");
ht.Add("Key5","Mahesh");

Here i am storing some names with some keywords

if i want to find key4 value

String name = ht["Keu4"];
this will return "JK"



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : how can i make table dynamicaly?
Previous : multipath routing
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use