- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 SortedList in C#
To get or set the value associated with specified key in SortedList, the code is as follows −
Example
using System; using System.Collections; public class Demo { public static void Main() { SortedList list = new SortedList (); list.Add("A", "Books"); list.Add("B", "Electronics"); list.Add("C", "Appliances"); list.Add("D", "Pet Supplies"); list.Add("E", "Clothing"); list.Add("F", "Footwear"); Console.WriteLine("Value associated with key E = "+list["E"]); list["E"] = "HDD"; Console.WriteLine("Value associated with key E [Updated] = "+list["E"]); } }
Output
This will produce the following output −
Value associated with key E = Clothing Value associated with key E [Updated] = HDD
Example
Let us see another example −
using System; using System.Collections; public class Demo { public static void Main() { SortedList list = new SortedList (); list.Add("A", "Books"); list.Add("B", "Electronics"); list.Add("C", "Appliances"); list.Add("D", "Pet Supplies"); list.Add("E", "Clothing"); list.Add("F", "Footwear"); Console.WriteLine("Value associated with key D = "+list["D"]); } }
Output
This will produce the following output −
Value associated with key D = Pet Supplies
- Related Articles
- Get or set the value associated with specified key in ListDictionary in C#
- Get or Set the value associated with specified key in Hashtable in C#
- Get or set the value associated with the specified key in StringDictionary in C#
- Remove the element with the specified key from a SortedList in C#
- Get the value associated with a given key in Java HashMap
- Gets or sets the value in HybridDictionary with specified key in C#
- Getting the index of the specified key in a SortedList object in C#
- Getting the key at the specified index of a SortedList object in C#
- Gets or sets the value at the specified key in StringDictionary in C#
- Get or Set at specified index in StringCollection in C#
- Getting index of the specified value in a SortedList object in C#
- How to add key/value pairs in SortedList in C#?
- Get or set the element at specified index in Collection in C#
- Modify the value associated with a given key in Java HashMap
- Get or set the element at the specified index in ArrayList in C#

Advertisements