![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get or set the value associated with specified key in ListDictionary in C#
To get or set the value associated with specified key in 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("A", "Books"); dict.Add("B", "Electronics"); dict.Add("C", "Appliances"); dict.Add("D", "Pet Supplies"); dict.Add("E", "Clothing"); dict.Add("F", "Footwear"); Console.WriteLine("Value associated with key C = "+dict["C"]); } }
Output
This will produce the following output −
Value associated with key C = Appliances
Example
Let us see another example −
using System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main() { ListDictionary dict = new ListDictionary(); dict.Add("A", "Books"); dict.Add("B", "Electronics"); dict.Add("C", "Appliances"); dict.Add("D", "Pet Supplies"); dict.Add("E", "Clothing"); dict.Add("F", "Footwear"); Console.WriteLine("Value associated with key C = "+dict["C"]); dict["C"] = "HDD"; Console.WriteLine("Value associated with key C [Updated] = "+dict["C"]); } }
Output
This will produce the following output −
Value associated with key C = Appliances Value associated with key C [Updated] = HDD
Advertisements