C# | Remove the entry with specified key from ListDictionary Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report 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 examples to illustrate the use of ListDictionary.Remove(Object) Method: Example 1: CSHARP // C# code to remove the entry with // the specified key from the ListDictionary using System; using System.Collections; using System.Collections.Specialized; class GFG { // Driver code public static void Main() { // Creating a ListDictionary named myDict ListDictionary myDict = new ListDictionary(); // Adding key/value pairs in myDict myDict.Add("Australia", "Canberra"); myDict.Add("Belgium", "Brussels"); myDict.Add("Netherlands", "Amsterdam"); myDict.Add("China", "Beijing"); myDict.Add("Russia", "Moscow"); myDict.Add("India", "New Delhi"); // To get count of key/value pairs in myDict Console.WriteLine("Total key/value pairs in myDict are : " + myDict.Count); // Displaying the key/value pairs in myDict Console.WriteLine("The key/value pairs in myDict are : "); foreach(DictionaryEntry de in myDict) { Console.WriteLine(de.Key + " " + de.Value); } // Remove the entry with the specified // key from the ListDictionary myDict.Remove("Russia"); // To get count of key/value pairs in myDict Console.WriteLine("Total key/value pairs in myDict are : " + myDict.Count); // Displaying the key/value pairs in myDict Console.WriteLine("The key/value pairs in myDict are : "); foreach(DictionaryEntry de in myDict) { Console.WriteLine(de.Key + " " + de.Value); } } } Output: Total key/value pairs in myDict are : 6 The key/value pairs in myDict are : Australia Canberra Belgium Brussels Netherlands Amsterdam China Beijing Russia Moscow India New Delhi Total key/value pairs in myDict are : 5 The key/value pairs in myDict are : Australia Canberra Belgium Brussels Netherlands Amsterdam China Beijing India New Delhi Example 2 : CSHARP // C# code to remove the entry with // the specified key from the ListDictionary using System; using System.Collections; using System.Collections.Specialized; class GFG { // Driver code public static void Main() { // Creating a ListDictionary named myDict ListDictionary myDict = new ListDictionary(); // Adding key/value pairs in myDict myDict.Add("I", "first"); myDict.Add("II", "second"); myDict.Add("III", "third"); myDict.Add("IV", "fourth"); myDict.Add("V", "fifth"); // To get count of key/value pairs in myDict Console.WriteLine("Total key/value pairs in myDict are : " + myDict.Count); // Displaying the key/value pairs in myDict Console.WriteLine("The key/value pairs in myDict are : "); foreach(DictionaryEntry de in myDict) { Console.WriteLine(de.Key + " " + de.Value); } // Remove the entry with the specified // key from the ListDictionary // This should raise "ArgumentNullException" // as the key is null myDict.Remove(null); // To get count of key/value pairs in myDict Console.WriteLine("Total key/value pairs in myDict are : " + myDict.Count); // Displaying the key/value pairs in myDict Console.WriteLine("The key/value pairs in myDict are : "); foreach(DictionaryEntry de in myDict) { Console.WriteLine(de.Key + " " + de.Value); } } } Runtime Error: Unhandled Exception: System.ArgumentNullException: Key cannot be null. Parameter name: key Note: If the ListDictionary does not contain an element with the specified key, the ListDictionary remains unchanged. No exception is thrown. This method is an O(n) operation, where n is Count. Reference : https://learn.microsoft.com/en-us/dotnet/api/system.collections.specialized.listdictionary.remove?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article C# | Removing the specified key entry from HybridDictionary S Sahil_Bansall Follow Improve Article Tags : C# CSharp-method CSharp-Specialized-Namespace CSharp-Specialized-ListDictionary Similar Reads C# | Remove entry with specified key from OrderedDictionary OrderedDictionary.Remove(Object) method is used to remove entry with the specified key from the OrderedDictionary collection. Syntax: public void Remove (object key); Here, key is the key of the entry to remove. Exceptions: NotSupportedException : If the OrderedDictionary collection is read-only. Ar 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# | Remove the entry at specified index from OrderedDictionary OrderedDictionary.RemoveAt(Int32) method is used to remove the entry at the specified index from the OrderedDictionary collection. Syntax: public void RemoveAt (int index); Here, index is the zero-based index of the entry to remove. Exceptions: NotSupportedException : If the OrderedDictionary collec 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 all entries from the ListDictionary ListDictionary.Clear method is used to remove the all entries from the ListDictionary. Syntax: public void Clear (); Below given are some examples to understand the implementation in a better way: Example 1: CSHARP // C# code to remove all entries // from the ListDictionary using System; using Syste 3 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