

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Gets or sets the value at the specified key in StringDictionary in C#
To get or set the value at the specified key in StringDictionary, the code is as follows −
Example
using System; using System.Collections.Specialized; public class Demo { public static void Main() { StringDictionary myDict = new StringDictionary(); myDict.Add("1", "Tablet"); myDict.Add("2", "Desktop"); myDict.Add("3", "Speakers"); myDict.Add("4", "Laptop"); myDict.Add("5", "Notebook"); myDict.Add("6", "Ultrabook"); myDict.Add("7", "HDD"); myDict.Add("8", "SDD"); myDict.Add("9", "Headphone"); myDict.Add("10", "Earphone"); Console.WriteLine("Value for key 5 = "+myDict["5"]); } }
Output
This will produce the following output −
Value for key 5 = Notebook
Example
Let us see another example −
using System; using System.Collections.Specialized; public class Demo { public static void Main() { StringDictionary myDict = new StringDictionary(); myDict.Add("1", "Tablet"); myDict.Add("2", "Desktop"); myDict.Add("3", "Speakers"); myDict.Add("4", "Laptop"); myDict.Add("5", "Notebook"); myDict.Add("6", "Ultrabook"); myDict.Add("7", "HDD"); myDict.Add("8", "SDD"); myDict.Add("9", "Headphone"); myDict.Add("10", "Earphone"); Console.WriteLine("Value for key 5 = "+myDict["5"]); myDict["5"] = "Flash Drive"; Console.WriteLine("Value for key 5 [Updated] = "+myDict["5"]); } }
Output
This will produce the following output −
Value for key 5 = Notebook Value for key 5 [Updated] = Flash Drive
- Related Questions & Answers
- Gets or sets the value in HybridDictionary with specified key in C#
- Gets or sets the element at the specified index in StringCollection in C#
- Gets or Sets the element at the specified index in the List in C#
- Get or set the value associated with the specified key in StringDictionary in C#
- Gets or sets the value of the bit at a specific position in the BitArray in C#
- Remove entry with specified key from the StringDictionary in C#
- Copy StringDictionary to Array at the specified index in C#
- Get the number of key/value pairs in the StringDictionary in C#
- Get or set the value associated with specified key in ListDictionary in C#
- Get or set the value associated with specified key in SortedList in C#
- Get or Set the value associated with specified key in Hashtable in C#
- Add key and value into StringDictionary in C#
- Add the specified key and value into the ListDictionary in C#
- Insert into OrderedDictionary with key and value at specified index in C#
- Getting the key at the specified index of a SortedList object in C#
Advertisements