VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/c-sharp-dictionary-remove-method/

⇱ C# | Dictionary.Remove Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C# | Dictionary.Remove Method

Last Updated : 11 Jul, 2025
This method is used to remove the value with the specified key from the Dictionary<TKey,TValue>. Syntax:
public bool Remove (TKey key);
Return Value: This method returns true if the element is successfully found and removed; otherwise it returns false. This method returns false if key is not found in the Dictionary. Exception: This method will give ArgumentNullException if the key is null. Below are the programs to illustrate the use of above-discussed method: Example 1:
Output:
Total key/value pairs in myDict are : 6
After remove operation
Total key/value pairs in myDict are : 5
Example 2:
Output:
Total key/value pairs in myDict are : 4
After remove operation
Total key/value pairs in myDict are : 3
Reference:
Comment

Explore