
- 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
Add key and value into StringDictionary in C#
To add key and value into StringDictionary, the code is as follows −
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"); strDict.Add("E", "Kevin"); strDict.Add("F", "Katie"); strDict.Add("G", "Brad"); Console.WriteLine("StringDictionary elements..."); foreach(DictionaryEntry de in strDict) { Console.WriteLine(de.Key + " " + de.Value); } } }
Output
This will produce the following output −
StringDictionary elements... a John b Andy c Tim d Ryan e Kevin f Katie g Brad
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("1", "Electric Cars"); strDict.Add("2", "SUV"); strDict.Add("3", "AUV"); Console.WriteLine("StringDictionary elements..."); foreach(DictionaryEntry de in strDict) { Console.WriteLine(de.Key + " " + de.Value); } } }
Output
This will produce the following output −
StringDictionary elements... 1 Electric Cars 2 SUV 3 AUV
- Related Articles
- Add key and value into OrderedDictionary collection in C#
- Add the specified key and value into the ListDictionary in C#
- Get the number of key/value pairs in the StringDictionary in C#
- Gets or sets the value at the specified key in StringDictionary in C#
- Get or set the value associated with the specified key in StringDictionary in C#
- Add key-value pair in C# Dictionary
- Adding the specified key and value into HybridDictionary in C#
- Remove entry with specified key from the StringDictionary in C#
- Check if the StringDictionary contains a specific key in C#
- How to add key/value pairs in SortedList in C#?
- Insert into OrderedDictionary with key and value at specified index in C#
- Create a TreeMap in Java and add key-value pairs
- Check if the StringDictionary contains a specific value in C#
- StringDictionary Class in C#?
- Add a key value pair to dictionary in Python

Advertisements