
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Removing all entries from the StringDictionary in C#
To remove all entries from the StringDictionary, the code is as follows −
Example
using System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main(){ StringDictionary strDict1 = new StringDictionary(); strDict1.Add("A", "John"); strDict1.Add("B", "Andy"); strDict1.Add("C", "Tim"); strDict1.Add("D", "Ryan"); strDict1.Add("E", "Kevin"); strDict1.Add("F", "Katie"); strDict1.Add("G", "Brad"); Console.WriteLine("StringDictionary1 elements..."); foreach(DictionaryEntry d in strDict1){ Console.WriteLine(d.Key + " " + d.Value); } Console.WriteLine("Does StringDictionary1 has key G? "+strDict1.ContainsKey("G")); StringDictionary strDict2 = new StringDictionary(); strDict2.Add("A", "John"); strDict2.Add("B", "Andy"); strDict2.Add("C", "Tim"); strDict2.Add("D", "Ryan"); strDict2.Add("E", "Kevin"); strDict2.Add("F", "Katie"); strDict2.Add("G", "Brad"); Console.WriteLine("
StringDictionary2 elements..."); foreach(DictionaryEntry d in strDict2){ Console.WriteLine(d.Key + " " + d.Value); } Console.WriteLine("Count of key/value pairs in StringDictionary2 = " + strDict2.Count); strDict2.Clear(); Console.WriteLine("Count of key/value pairs in StringDictionary2 (updated) = " + strDict2.Count); } }
Output
This will produce the following output −
StringDictionary1 elements... a John b Andy c Tim d Ryan e Kevin f Katie g Brad Does StringDictionary1 has key G? True StringDictionary2 elements... a John b Andy c Tim d Ryan e Kevin f Katie g Brad Count of key/value pairs in StringDictionary2 = 7 Count of key/value pairs in StringDictionary2 (updated) = 0
Example
Let us see another example −
using System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main(){ StringDictionary strDict = new StringDictionary(); strDict.Add("A", "John"); strDict.Add("B", "Andy"); strDict.Add("C", "Tim"); strDict.Add("D", "Ryan"); Console.WriteLine("StringDictionary elements..."); foreach(DictionaryEntry d in strDict){ Console.WriteLine(d.Key + " " + d.Value); } Console.WriteLine("Count of key/value pairs in StringDictionary = " + strDict.Count); strDict.Clear(); Console.WriteLine("Count of key/value pairs in StringDictionary (updated) = " + strDict.Count); } }
Output
This will produce the following output −
StringDictionary elements... a John b Andy c Tim d Ryan Count of key/value pairs in StringDictionary = 4 Count of key/value pairs in StringDictionary (updated) = 0
- Related Articles
- Removing all entries from HybridDictionary in C#
- Remove all entries from the ListDictionary in C#
- Removing all the elements from the List in C#
- Removing all nodes from LinkedList in C#
- Removing identical entries from an array keeping its length same - JavaScript
- Removing all the empty indices from array in JavaScript
- Remove entry with specified key from the StringDictionary in C#
- Efficient way to remove all entries from MongoDB?
- StringDictionary Class in C#?
- Removing all spaces from a string using JavaScript
- Removing the specified element from the List in C#
- Removing the specified node from the LinkedList in C#?
- Removing all non-alphabetic characters from a string in JavaScript
- MySQL query to select all entries from a particular month
- Removing the specified key entry from HybridDictionary in C#

Advertisements