C# | Remove the element with the specified key from the Hashtable Last Updated : 01 Feb, 2019 Comments Improve Suggest changes Like Article Like Report The Hashtable class represents a collection of key-and-value pairs that are organized based on the hash code of the key. The key is used to access the items in the collection. Hashtable.Remove(Object) Method is used to remove the element with the specified key from the Hashtable. Syntax: public virtual void Remove (object key); Parameter: key: It is the key of the element to remove of type System.Object. Exceptions: ArgumentNullException: If the key is null. NotSupportedException: If the Hashtable is read-only or has a fixed size. Example: CSHARP // C# code to remove the element // with the specified key from Hashtable using System; using System.Collections; class GFG { // Driver code public static void Main() { // Creating a Hashtable Hashtable myTable = new Hashtable(); // Adding elements in Hashtable myTable.Add("2", "Even & Prime"); myTable.Add("3", "Odd & Prime"); myTable.Add("4", "Even & non-prime"); myTable.Add("9", "Odd & non-prime"); // Print the number of entries in Hashtable Console.WriteLine("Total number of entries in Hashtable : " + myTable.Count); // To remove the elements from Hashtable // which has key as "3" myTable.Remove("3"); // Print the number of entries in Hashtable Console.WriteLine("Total number of entries in Hashtable : " + myTable.Count); // To remove the elements from Hashtable // which has key as "4" myTable.Remove("4"); // Print the number of entries in Hashtable Console.WriteLine("Total number of entries in Hashtable : " + myTable.Count); // Adding elements in Hashtable myTable.Add("g", "geeks"); myTable.Add("c", "c++"); myTable.Add("d", "data structures"); // Print the number of entries in Hashtable Console.WriteLine("Total number of entries in Hashtable : " + myTable.Count); // To remove the elements from Hashtable // which has key as "c" myTable.Remove("c"); // Print the number of entries in Hashtable Console.WriteLine("Total number of entries in Hashtable : " + myTable.Count); } } Output: Total number of entries in Hashtable : 4 Total number of entries in Hashtable : 3 Total number of entries in Hashtable : 2 Total number of entries in Hashtable : 5 Total number of entries in Hashtable : 4 Reference: https://docs.microsoft.com/en-us/dotnet/api/system.collections.hashtable.remove?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article C# | Remove the element with the specified key from the Hashtable S Sahil_Bansall Follow Improve Article Tags : Misc C# CSharp-method CSharp-Collections-Hashtable CSharp-Collections-Namespace +1 More Practice Tags : Misc Similar Reads C# | How to remove the element from the specified index of the List List<T>.RemoveAt (Int32) Method is used to remove the element at the specified index of the List<T>. Properties of List: It is different from the arrays. A list can be resized dynamically but arrays cannot. List class can accept null as a valid value for reference types and it also allow 3 min read C# | Remove the element with the specified key from a SortedList SortedList class is a collection of (key, value) pairs which are sorted according to keys. Those pairs can be accessible by key and as well as by index(zero-based indexing). This comes under System.Collections namespace. SortedList.Remove(Object) method is used to remove the element with the specifi 3 min read C# | Remove the specified element from a HashSet A HashSet is an unordered collection of the unique elements. It comes under System.Collections.Generic namespace. It is used in a situation where we want to prevent duplicates from being inserted in the collection. As far as performance is concerned, it is better in comparison to the list. HashSet 3 min read C# | Removing the specified element from the List List.Remove(T) Method is used to remove the first occurrence of a specific object from the List. Properties of List: It is different from the arrays. A list can be resized dynamically but arrays cannot. List class can accept null as a valid value for reference types and it also allows duplicate elem 2 min read C# | Remove entry with specified key from the StringDictionary StringDictionary.Remove(String) method is used to remove the entry with the specified key from the string dictionary. Syntax: public virtual void Remove (string key); Here, key is the key of the entry to remove. Exceptions: ArgumentNullException: If the key is null. NotSupportedException: If the Str 3 min read C# | Remove all elements from the Hashtable The Hashtable class represents a collection of key-and-value pairs that are organized based on the hash code of the key. The key is used to access the items in the collection. Hashtable.Clear Method is used to remove all elements from the Hashtable. Syntax: myTable.Clear() Here myTable is the name o 2 min read C# | Remove the entry with specified key from ListDictionary ListDictionary.Remove(Object) method is used to remove the entry with the specified key from the ListDictionary. Syntax: public void Remove (object key); Here, key is the key of the entry which is to be removed. Exception: This method will give ArgumentNullException if the key is null. Below are the 3 min read C# | Get or Set the value associated with specified key in Hashtable Hashtable.Item[Object] Property is used to get or set the value associated with the specified key in the Hashtable. Syntax: public virtual object this[object key] { get; set; } Here, key is key of object type whose value is to get or set. Exceptions: ArgumentNullException: If the key is null. NotSup 3 min read C# | Removing the specified key entry from HybridDictionary HybridDictionary.Remove(Object) method is used to remove the entry with the specified key from the HybridDictionary. Syntax: public void Remove (object key); Here, key is the key of the entry to remove. Exception: This method throws ArgumentNullException if the key is null. Below given are some exam 3 min read C# | How to get hash code for the specified key of a Hashtable Hashtable.GetHash(Object) method is used to get the hashcode of the specified key of a Hashtable object. This method is inherited from the Object Class. Syntax: protected virtual int GetHash(Object Key); Exception: This method will give NullReferenceException if the key is null. Below programs illus 2 min read Like