Blog
    C#
    ADO.Net
    .NET
    ASP.Net & Web Forms
    Custom Controls
    Web Development
    Exception Handling
    XML
    Database
    Security in .Net
    Testing
    Web Services
    Windows Services
    Windows Controls
    WCF
    AJAX
    WPF
    XAML
    Reporting
    Setup
    VB.Net
    LINQ
    JQuery
    SilverLight
    JavaScript
    HTML5
    Crystal Report
    Cloud Computing
    Share Point
    Visual C++
    MVC
    Android
    PHP
    Java
    HTML
    WordPress
    Joomla
    Products
    Drupal
    Windows Phone
    JSON
    LightSwitch
    iPhone/iPad
    Ruby on Rails
    IIS 7
    Windows 8
    CSS/CSS3
    Excel
    MS Access
    Shortcut Keys
    Visual SourceSafe
    Team Foundation Server
    API(s)
    Sencha-Touch
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Top Contributor
Advertisement
Advertise with Us
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog
Report Abuse Form
Reason:    
 

Home >> C# >> Hashtable in C#
Hashtable in C#

How to use a Hashtable in C#.
Views: 994     Comments: 0
by Uttam Misra on 5/18/2012

How to use a Hashtable in C#.

Creating a Hashtable

The following code creates a Hashtable:

private Hashtable hsTable = new Hashtable();

Adding Items to a Hashtable

Add method of Hashtable is used to add items to the hashtable. The method has index and value parameters.

The following code adds items to hashtable.

hsTable .Add("Game1",  "Cricket");
hsTable.Add("Game2",  "Football");
hsTable.Add("Game3",  "Badminton");
hsTable.Add("Game3",  "Basketball");

hsTable.Add("Game3",  "Tennis");

Retrieving an Item Value from Hashtable

The following code returns the value of "Cricket" key:

string name = hsTable ["Cricket "].ToString();

Removing Items from a Hashtable

The Remove method removes an item from a Hashtable.

The following code removes item with index "Cricket" from the hashtable:

hsTable.Remove("Cricket");

Looking through all Items of a Hashtable

The following code loops through all items of a hashtable and reads the values.


IDictionaryEnumerator en = hsTable.GetEnumerator();
while (en.MoveNext())
{
      string str = en.Value.ToString();
}

 

Title :  
Comment :
Text ColorBackground Color
BoldItalicUnderline
LeftCenterRightJustify
Ordered ListBulleted List
IndentOutdent
Horizontal Rule
SubscriptSuperscript
HyperlinkImage
Design ModeDesign
View HtmlHtml
       
 
Report Abuse Form
Reason:    
 
Latest ArticleRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Latest Blogs by Uttam MisraRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Top Viewed ArticlesRSS Feed
    
    
    
    
    
    
    
    
    
    
Top Viewed BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
Latest Interview QuestionsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Total Online Users: 2660
  
Copyright © 2009 - 2013MindStick. All Rights Reserved.