- 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
What is the Item property of SortedList class in C#?
A sorted list is a combination of an array and a hash table. It contains a list of items that can be accessed using a key or an index.
Gets and sets the value associated with a specific key in the SortedList.
You can also use the Item property to add new elements.
If a key does not exist, then you can include it like.
myCollection["myNonexistentKey"] = myValue
If the key already exist, then it will overwrite it with the new key and value.
The following is an example to learn how to work with Item property of SorteList class in C#.
Example
using System; using System.Collections; namespace Demo { class Program { static void Main(string[] args) { SortedList s = new SortedList(); s.Add("S001", "Jack"); s.Add("S002", "Henry"); s["S003"] = "Brad"; // get a collection of the keys. ICollection key = s.Keys; foreach (string k in key) { Console.WriteLine(k + ": " + s[k]); } } } }
Output
S001: Jack S002: Henry S003: Brad
Advertisements
To Continue Learning Please Login
Login with Google