
- 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
Remove entry with specified key from the StringDictionary in C#
To remove entry with specified key 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 key-value pairs..."); foreach(DictionaryEntry de in strDict1) { Console.WriteLine(de.Key + " " + de.Value); } strDict1.Remove("D"); Console.WriteLine("
StringDictionary1 key-value pairs after removing a key..."); foreach(DictionaryEntry de in strDict1) { Console.WriteLine(de.Key + " " + de.Value); } StringDictionary strDict2 = new StringDictionary(); strDict2.Add("1", "A"); strDict2.Add("2", "B"); strDict2.Add("3", "C"); strDict2.Add("4", "D"); strDict2.Add("5", "E"); Console.WriteLine("
StringDictionary2 key-value pairs..."); IEnumerator demoEnum = strDict2.GetEnumerator(); DictionaryEntry d; while (demoEnum.MoveNext()) { d = (DictionaryEntry)demoEnum.Current; Console.WriteLine("Key = " + d.Key + ", Value = " + d.Value); } } }
Output
This will produce the following output −
StringDictionary1 key-value pairs... a John b Andy c Tim d Ryan e Kevin f Katie g Brad StringDictionary1 key-value pairs after removing a key... a John b Andy c Tim e Kevin f Katie g Brad StringDictionary2 key-value pairs... Key = 1, Value = A Key = 2, Value = B Key = 3, Value = C Key = 4, Value = D Key = 5, Value = E
Example
Let us see another example −
using System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main() { StringDictionary strDict1 = new StringDictionary(); strDict1.Add("A", "One"); strDict1.Add("B", "Two"); strDict1.Add("C", "Three"); strDict1.Add("D", "Four"); strDict1.Add("E", "Five"); Console.WriteLine("StringDictionary1 key-value pairs..."); foreach(DictionaryEntry de in strDict1) { Console.WriteLine(de.Key + " " + de.Value); } strDict1.Remove("B"); strDict1.Remove("C"); Console.WriteLine("
StringDictionary1 key-value pairs after removing a key..."); foreach(DictionaryEntry de in strDict1) { Console.WriteLine(de.Key + " " + de.Value); } } }
Output
This will produce the following output −
StringDictionary1 key-value pairs... a One b Two c Three d Four e Five StringDictionary1 key-value pairs after removing a key... a One d Four e Five
- Related Articles
- Remove entry with specified key from OrderedDictionary in C#
- Remove the entry with specified key from ListDictionary in C#
- Removing the specified key entry from HybridDictionary in C#
- Remove the entry at specified index from OrderedDictionary in C#
- Remove the element with the specified key from the Hashtable in C#
- Remove the element with the specified key from a SortedList in C#
- Get or set the value associated with the specified key in StringDictionary in C#
- Gets or sets the value at the specified key in StringDictionary in C#
- Insert a new entry in OrderedDictionary with specified key and value in C#
- C++ Remove an Entry Using Key from HashMap while Iterating Over It
- How to remove Lua table entry by its key?
- Copy StringDictionary to Array at the specified index in C#
- Add key and value into StringDictionary in C#
- Check if the StringDictionary contains a specific key in C#
- Remove specified element from HashSet in Java

Advertisements