Hash Table in Collection Classes

Posted on Updated on

ouooHash Table

The Hashtable class is a collection of key-and-value pairs that are structured based on the hash code of the key. It uses the key to access the elements in the collection. It is used when access of elements is to be performed by using key, and corresponding key value received. Each item in the hash table has a key/value pair. The key is used to access the items in the collection.

Methods and Properties of the Hashtable Class

Property                      Description

Count                                        Gets the number of key-and-value pairs contained in the Hashtable.

IsFixedSize                              Gets a value indicating whether the Hashtable has a fixed size.

IsReadOnly                              Gets a value indicating whether the Hashtable is read-only.

Item                                          Gets or sets the value associated with the specified key.

Keys                                          Gets an ICollection containing the keys in the Hashtable.

Values                                       Gets an ICollection containing the values in the Hashtable.

Sr.No.                              Method

1                                                  public virtual void Add(object key, object value);

2                                                  public virtual void Clear();

3                                                  virtual bool ContainsKey(object key);

4                                                  public virtual bool ContainsValue(object value);

5                                                 public virtual void Remove(object key);


using System;

using System.Collections;

namespace CollectionsApplication


class Program


static void Main(string[] args)


Hashtable ht = new Hashtable();

ht.Add(“001”, “Zara Ali”);

ht.Add(“002”, “Abida Rehman”);

ht.Add(“003”, “Joe Holzner”);

ht.Add(“004”, “Mausam Benazir Nur”);

ht.Add(“005”, “M. Amlan”);

ht.Add(“006”, “M. Arif”);

ht.Add(“007”, “Ritesh Saikia”);

if (ht.ContainsValue(“Nuha Ali”))


Console.WriteLine(“This student name is already in the list”);




ht.Add(“008”, “Nuha Ali”);


// Get a collection of the keys.

ICollection key = ht.Keys;

foreach (string k in key)


Console.WriteLine(k + “: ” + ht[k]);







For more details and queries please feel free to email, visit or call us. Wishing you the very best for all your future endeavors.
Helpline: 9814666333, 8699444666
Email: info@technocampus.co.in

Please fill the form and we shall contact you soon.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s