Shilpa Nadkarni

Shilpa Nadkarni

13 Articles Published

Articles by Shilpa Nadkarni

13 articles

C# Program to Check a HashTable collection is empty or not

Shilpa Nadkarni
Shilpa Nadkarni
Updated on 17-Mar-2026 2K+ Views

The Hashtable collection in C# is a collection of key-value pairs organized based on the hash code of the key. Each element is a key-value pair with unique keys, and keys cannot be null. Values can be null and duplicated. In this article, we will explore different methods to check if a Hashtable collection is empty or not. Syntax Following is the syntax for checking if a Hashtable is empty using the Count property − if (hashtable.Count == 0) { // Hashtable is empty } The Count property returns an ...

Read More

C# Program to Check if Value exists in Hashtable

Shilpa Nadkarni
Shilpa Nadkarni
Updated on 17-Mar-2026 2K+ Views

The hashtable is an organized collection of key-value pairs wherein the keys are arranged as per the hash code of the key calculated using the hash function. While the keys should be non-null and unique in a hashtable, the values can be null and duplicate. The elements in the hashtable are accessed using the keys. In C#, the class Hashtable represents the hashtable collection. This class provides various properties and methods using which we can perform operations and access data in the hashtable. In this article, we will see how we can determine if a particular value is ...

Read More

C# Program to Get Key based on Value in Hashtable Collection

Shilpa Nadkarni
Shilpa Nadkarni
Updated on 17-Mar-2026 1K+ Views

A hashtable is a collection in C# that holds items identified as key-value pairs. Unlike other data structures like the stack, queue, or ArrayList that store a single value, a hashtable stores two values that form an element − the key and the value. In a hashtable, the keys are unique and cannot be null. The values can be null and duplicated. The System.Collections namespace provides the Hashtable class with various constructors, methods, and properties to perform operations on hashtable objects. This article demonstrates how to retrieve a key from a hashtable collection based on a specific value. ...

Read More

C# Program to Merge Two Hashtable Collections

Shilpa Nadkarni
Shilpa Nadkarni
Updated on 17-Mar-2026 749 Views

The Hashtable collection in C# stores key-value pairs where each element is a DictionaryEntry object. The key is unique and non-null, used to access elements in the hashtable. Values can be null or duplicated, but the combination of key-value pairs must be unique. Since the Hashtable class doesn't provide a built-in merge method, we need to implement our own approach by iterating through one hashtable and adding its elements to another while checking for duplicate keys. Syntax Following is the syntax for creating and populating a Hashtable − Hashtable hashtableName = new Hashtable(); hashtableName.Add(key, value); ...

Read More

C# Program to Print the Length of the Hashtable

Shilpa Nadkarni
Shilpa Nadkarni
Updated on 17-Mar-2026 875 Views

A Hashtable in C# is a collection that stores key-value pairs, where each key is unique and used to access its corresponding value. Unlike arrays or lists, Hashtables don't have a direct Length property, but we can determine the number of elements using the Count property. The Hashtable class belongs to the System.Collections namespace and organizes elements based on the hash code of their keys. Keys must be unique and non-null, while values can be duplicated or null. Syntax The Count property returns the number of key-value pairs in the Hashtable − public virtual int ...

Read More

How to Add Items to Hashtable Collection in C#

Shilpa Nadkarni
Shilpa Nadkarni
Updated on 17-Mar-2026 899 Views

A Hashtable collection in C# stores key-value pairs using a hash-based mechanism. Each key-value pair is organized based on the hash code of the key, which is calculated using a hash function. Unlike modern generic collections, hashtables can store objects of different data types but exhibit lower performance due to boxing and unboxing operations. In this article, we will explore how to add items to a hashtable collection using various methods available in the Hashtable class. Syntax The primary method for adding items to a hashtable is the Add() method − public virtual void Add(object ...

Read More

How to Check if a Key Exists in the Hashtable in C#?

Shilpa Nadkarni
Shilpa Nadkarni
Updated on 17-Mar-2026 2K+ Views

The Hashtable class in C# represents a collection of key-value pairs organized based on the hash code of each key. In hashtables, keys are unique and non-null, while values can be null or duplicated. Often, you need to verify whether a specific key exists before performing operations like retrieval or updates. C# provides two methods to check if a key exists in a hashtable: ContainsKey() and Contains(). Both methods serve the same purpose but have slightly different naming conventions for clarity. Syntax Following is the syntax for the ContainsKey() method − public virtual bool ContainsKey(object ...

Read More

How to Create a HashTable Collection in C#?

Shilpa Nadkarni
Shilpa Nadkarni
Updated on 17-Mar-2026 295 Views

The Hashtable is a non-generic collection in C# that stores key-value pairs, similar to a generic Dictionary collection. Hashtable is defined in the System.Collections namespace and computes hash codes for keys to optimize lookups by storing them in different internal buckets. In this tutorial, we will see how to create a Hashtable collection in C# using different approaches. Key Features of Hashtable Stores key-value pairs as DictionaryEntry objects Keys must be unique and non-null, but values can be null or duplicate Keys are immutable objects that provide hash functions Values can be accessed using keys in ...

Read More

How to Delete Item from Hashtable Collection in C#?

Shilpa Nadkarni
Shilpa Nadkarni
Updated on 17-Mar-2026 592 Views

The Hashtable in C# is a collection of key-value pairs that are organized based on the hash code of the key. Items in the hashtable are accessed using a key, and the Hashtable class provides various methods to perform operations like adding, removing, and checking for the existence of specified keys. In this article, we will discuss how to delete an item from the hashtable collection using a specified key with the Remove() method. Syntax The Hashtable class provides the Remove() method to delete an item from the hashtable collection − public virtual void Remove(object ...

Read More

How to get keys from a HashTable in C#?

Shilpa Nadkarni
Shilpa Nadkarni
Updated on 17-Mar-2026 526 Views

The Hashtable is a non-generic collection in C# that stores key-value pairs, similar to the generic Dictionary collection. It is defined in the System.Collections namespace. A Hashtable consists of key/value pairs where each key is computed as a hash code and stored in different buckets internally. When accessing the Hashtable, this hash code is matched to locate the corresponding value, which optimizes lookup performance. Let's explore how to retrieve keys from a Hashtable in C#. Syntax Following is the syntax for accessing Hashtable keys using a foreach loop − foreach(DictionaryEntry entry in hashtable) { ...

Read More
Showing 1–10 of 13 articles
« Prev 1 2 Next »
Advertisements