C# | Remove the element with the specified key from the Hashtable Last Updated : 01 Feb, 2019 Summarize Comments Improve Suggest changes Share 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 Like