- 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
SortedMap Interface in C#
Java has SortedMap Interface, whereas an equivalent of it in C# is SortedList.
SortedList collection in C# use a key as well as an index to access the items in a list.
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. If you access items using an index, it is an ArrayList, and if you access items using a key, it is a Hashtable. The collection of items is always sorted by the key value.
Let us see an example to work with SortedList and display the keys −
Example
using System; using System.Collections; namespace Demo { class Program { static void Main(string[] args) { SortedList sl = new SortedList(); sl.Add("ST0", "One"); sl.Add("ST1", "Two"); sl.Add("ST2", "Three"); ICollection key = sl.Keys; foreach(string k in key) { Console.WriteLine(k); } } } }
Output
ST0 ST1 ST2
Advertisements