C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




How to use Hash Table in .Net


Posted Date: 15 May 2008    Resource Type: Code Snippets    Category: ASP.NET WebForms
Author: mani kumar.k.mMember Level: Gold    
Rating: Points: 10



The following code shows how to use Hash Table in .Net

In this article, describes about hashtable and how to use it. 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 and some important accessing with hash table is described below. The data type of Hashtable is object and the default size of a Hashtable is 16.


Hashtable is a member of System.Collections namespace.

Declaration of hashtable



Hashtable Mytable = new Hashtable();

Adding elemets in to Hashtable


Mytable.Add("Key1", "Vaue1");
Mytable.Add("Key2", 2);


Number of elements in the hashtable


Mytable.Count // is an integer value

For getting the values from the hashtable


foreach (object o in Mytable.Values)
{
MessageBox.Show(o.ToString());
}


For getting the values according to a specific key


IDictionaryEnumerator Myenumerator = Mytable.GetEnumerator();
while (Myenumerator.MoveNext())
{
if (Myenumerator.Key=="Key1")
{
MessageBox.Show(Myenumerator.Value.ToString());
}
}




if (!Mytable.ContainsKey("Key1"))
{
MessageBox.Show("Value for the key = \"Key1\":"+ Mytable["Key1"].ToString());
}






Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Hashtable  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: How to Encrypt and Decrypt Password
Previous Resource: How to get Image from database to ASP.Net page
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET WebForms


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use