
- 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 the specified key and value into the ListDictionary in C#
To add the specified key and value into the ListDictionary, the code is as follows −
Example
using System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main(){ ListDictionary dict = new ListDictionary(); dict.Add("1", "One"); dict.Add("2", "Two"); dict.Add("3", "Three"); dict.Add("4", "Four"); dict.Add("5", "Five"); Console.WriteLine("ListDictionary key-value pairs..."); IDictionaryEnumerator demoEnum = dict.GetEnumerator(); while (demoEnum.MoveNext()) Console.WriteLine("Key = " + demoEnum.Key + ", Value = " + demoEnum.Value); } }
Output
This will produce the following output −
ListDictionary key-value pairs... Key = 1, Value = One Key = 2, Value = Two Key = 3, Value = Three Key = 4, Value = Four Key = 5, Value = Five
Example
Let us now see another example −
using System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main(){ ListDictionary listDict = new ListDictionary(); listDict.Add("1", 100); listDict.Add("2", 200); listDict.Add("3", 300); listDict.Add("4", 400); listDict.Add("5", 500); listDict.Add("6", 600); listDict.Add("7", 700); listDict.Add("8", 800); listDict.Add("9", 900); listDict.Add("10", 1000); ICollection col = listDict.Keys; Console.WriteLine("Display all the keys..."); foreach(String s in col){ Console.WriteLine(s); } } }
Output
This will produce the following output −
Display all the keys... 1 2 3 4 5 6 7 8 9 10
- Related Articles
- Get or set the value associated with specified key in ListDictionary in C#
- Adding the specified key and value into HybridDictionary in C#
- Remove the entry with specified key from ListDictionary in C#
- Add key and value into StringDictionary in C#
- Add key and value into OrderedDictionary collection in C#
- Insert into OrderedDictionary with key and value at specified index in C#
- Get the number of key/value pairs contained in ListDictionary in C#
- Gets or sets the value at the specified key in StringDictionary in C#
- Copy ListDictionary to Array instance at the specified index in C#
- Gets or sets the value in HybridDictionary with specified key in C#
- Get or set the value associated with the specified key in StringDictionary in C#
- Add text and number into specified position of cell in Excel
- Get or Set the value associated with specified key in Hashtable in C#
- Get or set the value associated with specified key in SortedList in C#
- Insert a new entry in OrderedDictionary with specified key and value in C#

Advertisements