| Author: krish 24 Sep 2008 | Member Level: Gold | Rating:  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 2008 | Member Level: Gold | Rating:  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 2008 | Member Level: Gold | Rating:  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 2008 | Member Level: Silver | Rating:  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 2008 | Member Level: Gold | Rating:  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"
|