- 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 the specified key in StringDictionary in C#
To get or set the value associated with specified key in StringDictionary, the code is as follows −
Example
using System; using System.Collections.Specialized; public class Demo { public static void Main() { StringDictionary strDict = new StringDictionary (); strDict.Add("A", "Books"); strDict.Add("B", "Electronics"); strDict.Add("C", "Appliances"); strDict.Add("D", "Pet Supplies"); strDict.Add("E", "Clothing"); strDict.Add("F", "Footwear"); Console.WriteLine("Value associated with key D = "+strDict["D"]); Console.WriteLine("Value associated with key F = "+strDict["F"]); } }
Output
This will produce the following output −
Value associated with key D = Pet Supplies Value associated with key F = Footwear
Example
Let us see another example −
using System; using System.Collections.Specialized; public class Demo { public static void Main() { StringDictionary strDict = new StringDictionary (); strDict.Add("A", "Books"); strDict.Add("B", "Electronics"); strDict.Add("C", "Appliances"); strDict.Add("D", "Pet Supplies"); strDict.Add("E", "Clothing"); strDict.Add("F", "Footwear"); Console.WriteLine("Value associated with key D = "+strDict["D"]); Console.WriteLine("Value associated with key F = "+strDict["F"]); strDict["F"] = "HDD"; Console.WriteLine("Value associated with key F (UPDATED) = "+strDict["F"]); } }
Output
This will produce the following output −
Value associated with key D = Pet Supplies Value associated with key F = Footwear Value associated with key F (UPDATED) = HDD
Advertisements