Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • C# Data Types
  • C# Decision Making
  • C# Methods
  • C# Delegates
  • C# Constructors
  • C# Arrays
  • C# ArrayList
  • C# String
  • C# Tuple
  • C# Indexers
  • C# Interface
  • C# Multithreading
  • C# Exception
Open In App
Next Article:
C# | Remove all entries from the ListDictionary
Next article icon

C# | Removing all entries from the StringDictionary

Last Updated : 01 Feb, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
StringDictionary.Clear method is used to remove all the entries from the StringDictionary. Syntax:
  public virtual void Clear ();  
Exception: This method will give the NotSupportedException if the StringDictionary is read-only. Example: CSHARP
// C# code to remove all entries // from the StringDictionary using System; using System.Collections; using System.Collections.Specialized;  class GFG {      // Driver code     public static void Main()     {          // Creating a StringDictionary named myDict         StringDictionary myDict = new StringDictionary();          // Adding key and value into the StringDictionary         myDict.Add("A", "Apple");         myDict.Add("B", "Banana");         myDict.Add("C", "Cat");         myDict.Add("D", "Dog");         myDict.Add("E", "Elephant");         myDict.Add("F", "Fish");          // Displaying the keys and values in StringDictionary         Console.WriteLine("The number of key/value pairs are : " + myDict.Count);          foreach(DictionaryEntry dic in myDict)         {             Console.WriteLine(dic.Key + " " + dic.Value);         }          // Removing all entries from the StringDictionary         myDict.Clear();          // Displaying the keys and values in StringDictionary         Console.WriteLine("The number of key/value pairs are : " + myDict.Count);          foreach(DictionaryEntry dic in myDict)         {             Console.WriteLine(dic.Key + " " + dic.Value);         }     } } 
Output:
  The number of key/value pairs are : 6  b Banana  c Cat  a Apple  f Fish  d Dog  e Elephant  The number of key/value pairs are : 0  
Note: This method is an O(n) operation, where n is Count. Reference:
  • https://docs.microsoft.com/en-us/dotnet/api/system.collections.specialized.stringdictionary.clear?view=netframework-4.7.2

Next Article
C# | Remove all entries from the ListDictionary

S

Sahil_Bansall
Improve
Article Tags :
  • C#
  • CSharp-method
  • CSharp-Collections-Namespace
  • CSharp-Specialized-StringDictionary
  • CSharp-Specialized-Namespace

Similar Reads

  • 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: // C# code to remove all entries // from the ListDictionary using System; using System.Colle
    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
  • How to create a StringDictionary in C#
    StringDictionary() constructor is used to initialize a new instance of the StringDictionary class which will be empty and will have the default initial capacity. StringDictionary is a specialized collection. This class comes under the System.Collections.Specialized namespace. It only allows string k
    2 min read
  • C# | Removing all entries from HybridDictionary
    HybridDictionary.Clear method is used to remove all entries from the HybridDictionary. Syntax: public void Clear (); Below given are some examples to understand the implementation in a better way : Example 1: // C# code to removes all entries // from the HybridDictionary. using System; using System.
    3 min read
  • C# | Check if the StringDictionary contains a specific key
    StringDictionary.ContainsKey(String) method is used to check whether the StringDictionary contains a specific key or not. Syntax: public virtual bool ContainsKey (string key); Here, key is the key to locate in the StringDictionary. Return Value: This method returns true if the StringDictionary conta
    2 min read
  • C# | Remove all elements from the SortedSet
    SortedSet class represents the collection of objects in sorted order. This class comes under the System.Collections.Generic namespace. SortedSet<T>.Clear Method is used to remove the all elements from the SortedSet. Properties: In C#, SortedSet class can be used to store, remove or view elements.
    2 min read
  • C# | Remove all the strings from the StringCollection
    StringCollection class is a new addition to the .NET Framework class library that represents a collection of strings. StringCollection class is defined in the System.Collections.Specialized namespace. StringCollection.Clear method is used to remove all the strings from the StringCollection. Syntax:
    2 min read
  • C# | Remove all elements from OrderedDictionary
    OrderedDictionary.Clear method is used to remove all elements from the OrderedDictionary collection. Syntax: public void Clear (); Exception: If the OrderedDictionary collection is read-only then it will throw NotSupportedException. Below given are some examples to understand the implementation in a
    2 min read
  • C# | Check if the StringDictionary contains a specific value
    StringDictionary.ContainsValue(String) method is used to check whether the StringDictionary contains a specific value or not. Syntax: public virtual bool ContainsValue (string value); Here, value is the value to locate in the StringDictionary. The value can be null. Return Value: The method returns
    2 min read
  • C# | Get a collection of keys in the StringDictionary
    StringDictionary.Keys property is used to get a collection of keys in the StringDictionary. Syntax: public virtual System.Collections.ICollection Keys { get; } Return Value: An ICollection that provides the keys in the StringDictionary. Below given are some examples to understand the implementation
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences