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 !






Hashtable - basic operations


Posted Date: 20 Jun 2008    Resource Type: Code Snippets    Category: Collections

Posted By: Kapil Dhawan       Member Level: Gold
Rating:     Points: 7



The code sample in C# explains the basic operations on a Hashtable. A Hashtable is an object that stores (key,value) pairs. With such an object, storing and searching data becomes easier.

The example describes operations such as - creation of a Hashtable, inserting data, accessing data from a hashtable and deleting values.



using System.Collections; //for hashtable


//Create a Hashtable
Hashtable ohash = new Hashtable();


//Add data using the Add() method
ohash.Add("US", "UNITED STATE");
ohash.Add("IN", "INDIA");
ohash.Add("PAK", "PAKISTAN");

//value are stored in key and value pair in hashtable
//to fetch the value we use key name, for example
string countryName = ohash["US"].ToString();

//to delete any record, we will also use key name, for example
ohash.Remove("US");

//now to fetch all the values from hashtable
IDictionaryEnumerator oIDic = ohash.GetEnumerator();
while (oIDic.MoveNext())
{
Response.Write(oIDic.Value.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  
Using Hashtable in C#  .  Using Hashtable  .  Operations on a Hashtable  .  Inserting data in Hashtables  .  Hashtable in c#  .  Deleting data in Hastables  .  Basic operations on a 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: Max/Min values
Previous Resource: Convert from String Array to List<t>
Return to Discussion Resource Index
Post New Resource
Category: Collections


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

UK Conference calling Company

Contact Us    Privacy Policy    Terms Of Use